Feb2019 Round Flashcards
deleteing elements from a set
set.discard(x) or set.remove(x)
difference between set.remove and set.discard
set. discard - no error if x is not there
set. remove - error if x is not there
adding elements to the set
set.update or set.add
difference between set.update and set.add
set. update - arg must be iteratble
set. add - arg must be a singleton
removing elements from a list when you know the index
del(a[index])
removing elements from list by value (say value is x)
a.remove(x)
add elements to the end of the list
list.append(x) or list.extend(x)
difference between list.append and list.extend
list. extend() –> needs an iterable
list. append() –> takes only a singleton
delete value from a dict with key = k
del(d[k])
what is the difference between range and xrange?
xrange produces one element at a time as and when you need it whereas range creates all at once.
getting value of an element with key k from dict d. return 0 if k not present in d
d.get(k,0)