Feb2019 Round Flashcards

1
Q

deleteing elements from a set

A

set.discard(x) or set.remove(x)

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

difference between set.remove and set.discard

A

set. discard - no error if x is not there

set. remove - error if x is not there

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

adding elements to the set

A

set.update or set.add

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

difference between set.update and set.add

A

set. update - arg must be iteratble

set. add - arg must be a singleton

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

removing elements from a list when you know the index

A

del(a[index])

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

removing elements from list by value (say value is x)

A

a.remove(x)

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

add elements to the end of the list

A

list.append(x) or list.extend(x)

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

difference between list.append and list.extend

A

list. extend() –> needs an iterable

list. append() –> takes only a singleton

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

delete value from a dict with key = k

A

del(d[k])

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

what is the difference between range and xrange?

A

xrange produces one element at a time as and when you need it whereas range creates all at once.

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

getting value of an element with key k from dict d. return 0 if k not present in d

A

d.get(k,0)

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