Python Data Structures and Their Methods

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/52

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

53 Terms

1
New cards

append(x)

Add item to end of list

2
New cards

pop([i])

Remove and return item (default is last)

3
New cards

insert(i, x)

Insert item at index

4
New cards

remove(x)

Remove first occurrence of value

5
New cards

reverse()

Reverse list in place

6
New cards

sort()

Sort list in place

7
New cards

extend(iterable)

Add items from another iterable

8
New cards

count(x)

Count number of times value appears

9
New cards

index(x)

Return first index of value

10
New cards

len(lst)

Get number of elements

11
New cards

list[start:end:step]

Slice list

12
New cards

add(x)

Add element

13
New cards

discard(x)

Remove if exists

14
New cards

union(set2)

Combine sets

15
New cards

intersection(set2)

Common elements

16
New cards

difference(set2)

Elements in one but not the other

17
New cards

in

Check membership

18
New cards

len(set)

Get size

19
New cards

get(key, default)

Get value or default

20
New cards

keys()

All keys

21
New cards

values()

All values

22
New cards

items()

All key-value pairs

23
New cards

pop(key)

Remove key and return value

24
New cards

update(other_dict)

Add/replace items from another dict

25
New cards

len(dict)

Number of key-value pairs

26
New cards

split(sep)

Split into list

27
New cards

join(list)

Join list into string

28
New cards

strip()

Remove surrounding whitespace

29
New cards

startswith(s)

Check start

30
New cards

endswith(s)

Check end

31
New cards

replace(old, new)

Replace substring

32
New cards

find(s)

Find index of substring

33
New cards

lower()

To lowercase

34
New cards

upper()

To uppercase

35
New cards

len(s)

Length of string

36
New cards

s[start:end]

Slice string

37
New cards

range(n)

Sequence from 0 to n-1

38
New cards

enumerate(iterable)

Index + value

39
New cards

zip(a, b)

Pair elements

40
New cards

map(func, iterable)

Apply function

41
New cards

filter(func, iterable)

Filter by function

42
New cards

any(iterable)

True if any True

43
New cards

all(iterable)

True if all True

44
New cards

sum(iterable)

Total of items

45
New cards

max(iterable)

Largest value

46
New cards

min(iterable)

Smallest value

47
New cards

sorted(iterable)

Return sorted version

48
New cards

heapq.heappush(heap, x)

Add to min-heap

49
New cards

heapq.heappop(heap)

Remove min from heap

50
New cards

deque.append(x)

Add to right side

51
New cards

deque.popleft()

Remove from left side

52
New cards

collections.Counter()

Count frequencies

53
New cards

collections.defaultdict(type)

Auto-creating dict