Practice Flashcards

1
Q

Remove an item from a list

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Reverse list

A

.reverse() in place, only for list
reversed() returns iterator
(if the input list changes iterator sees it)
[::-1] reversed copy, slow

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Sequence Functions

A

len()
min()
max()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Functions that return iterator

A

reversed(), enumerate(), zip(), map(), filter()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Generator usage

A

infinite sequence

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Map

A

map(function, iterables)
map object
transformation function
lambda function (don’t use!)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Filter

A

map(function, iterable)
map(None, iterable) True elements
lambda function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Generator expression without ()

A

list(square(x) for x in numbers)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Sum

A

sum(iterable, start)
start = 0
can’t sum strings

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Zip

A

zip(iterables)
zip(
result_iterable)
dict(zip(fields, values))
strict

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Enumerate

A

enumerate(iterable, start=0)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Dictionary update()

A

dict.update(iterable or kwargs)
iterable: dict, iterable of tuples etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Sort

A

sort(*, key=None, reverse=False)
list.sort()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Max, Min

A

max(iterable, key, default)
max(arg1, arg2, *args, key)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

All, Any

A

all(iterable)
True if iterable is empty

any(iterable)
False if iterable is empty

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Is Instance

A

isinstance(object, classinfo)
classinfo - type, class, tuple of types and/or classes

17
Q

Sorted

A

sorted(iterable, /, *, key=None, reverse=False)
returns a list

18
Q

Dictionary Creation

A
  • dict(dict1)
  • dict(iterable of (key, value))
  • merge: dict1 | dict2
  • merge into a literal: {…, **dict1, …}
19
Q

Is Subclass

A

issubclass(class, classinfo)
classinfo - class, tuple of classes