My Tech Notes
Showing posts with label
list
.
Show all posts
Showing posts with label
list
.
Show all posts
Python: remove an item from list while iterating the list
›
list[:] = [item for item in list if match(item)] The above code removes the matching items in the list without constructing a new list, th...
Python: empty a list
›
del list[:] list[:]=[]
Python: delete a item from a list
›
remove the first matching element: if e in list: list.remove(e) remove all occurrences: while e in list: list.remove(e) EAFP style: ...
python: join lists
›
list1 = ['a', 'b'] list2 = ['c', 'd'] list3 = list1 + list2
Python: check if a list is empty
›
if not a: print('empty')
Python: list comprehension
›
To transform a list to another: list2 = [ unicode(e.strip()) for e in list1 ] To transform a list to another conditionally: list2 = [ unicod...
›
Home
View web version