1. Arrays / Lists

When Used:

Key Operations:

Operation Time
Access arr[i] O(1)
Append O(1)
Insert/delete middle O(n)
Search O(n)
Sort O(n log n)

Useful Syntax:

nums = [1,2,3]

nums.append(4)
nums.pop()
nums.sort()
nums.reverse()

for i, v in enumerate(nums):
    pass

Patterns:


2. Strings

Strings behave like arrays but are immutable.

Useful Operations:

s = "hello"

s[0]
s[1:4]
len(s)

s.lower()
s.upper()

s.split()
" ".join(list_of_words)

s.replace("a","b")

c.isdigit()
c.isalpha()

Common Problems: