← 30 Days of Python
Day 3 / 30Lists

Lists — Operations & Methods

Lists are the most-used Python collection in data work. You will use them to store column names, filter conditions, and results from loops. Interviewers test lists heavily.

1
Easy

How do you create a list and access elements?

Python Answer
cols = ["name", "age", "salary"]
cols[0]    # "name"
cols[-1]   # "salary"  (last element)
cols[1:3]  # ["age", "salary"]  (slicing)
💡

Negative indexing (-1 for last) and slicing are Python-specific. In data work, you frequently build lists of column names to select or drop from a DataFrame.

2
Easy

How do you add and remove items from a list?

Python Answer
lst = [1, 2, 3]
lst.append(4)      # [1, 2, 3, 4]
lst.extend([5, 6]) # [1, 2, 3, 4, 5, 6]
lst.insert(0, 0)   # [0, 1, 2, 3, 4, 5, 6]
lst.remove(3)      # removes first occurrence of 3
lst.pop()          # removes and returns last item
💡

append() adds one item; extend() adds multiple. pop() is useful when processing items one by one. remove() deletes by value, pop() by position.

3
Easy

How do you sort a list?

Python Answer
nums = [3, 1, 4, 1, 5, 9]
nums.sort()              # sorts in place: [1, 1, 3, 4, 5, 9]
sorted(nums)             # returns new sorted list
nums.sort(reverse=True)  # descending
💡

.sort() modifies the original list. sorted() returns a new one and works on any iterable. In data analysis, you often sort value lists before mapping to charts.

4
Medium

What is a list comprehension and when do you use it?

Python Answer
# Without comprehension:
squares = []
for x in range(5):
    squares.append(x**2)

# With list comprehension (preferred):
squares = [x**2 for x in range(5)]   # [0, 1, 4, 9, 16]

# With condition:
evens = [x for x in range(10) if x % 2 == 0]
💡

List comprehensions are faster and more Pythonic. Interviewers love asking this. Use them to transform or filter lists in one line — e.g. [c.upper() for c in col_names].

5
Easy

How do you find the length, min, max, and sum of a list?

Python Answer
nums = [10, 20, 30, 40]
len(nums)   # 4
min(nums)   # 10
max(nums)   # 40
sum(nums)   # 100
💡

These built-ins work on any iterable. Before Pandas, these are your quick stats on a raw list. They also work on Pandas Series.

6
Easy

How do you check if an item exists in a list?

Python Answer
cols = ["name", "age", "salary"]
"age" in cols      # True
"gender" in cols   # False
💡

The in operator for lists has O(n) time complexity — it scans every element. For large collections with frequent lookups, use a set instead, which is O(1).

EVIKA ACADEMY · PYTHON FOR DATA ANALYTICS

Want to master Python with live practice?

Join our Python for Data Analysis course — live classes in Noida and online across India.

Book Free Demo Class →
← PREVIOUSDay 2: Strings — Manipulation & MethodsNEXT →Day 4: Dictionaries & Sets
Best Data Analytics Course in Noida Delhi NCR | EVIKA ACADEMY