ListsA list is a data structure that contains a series of values. Python allows the construction of a list containing values of different types. It's iterable, indexable, ordered, mutable and not hashable. combination of lists and dictionaries
But the keys of dictionary are hasables, not ordered and not duplicated. list[:] is a new list duplicating the original, so list[:][0] will return the first element of the list Operation in the lists
- We cannont substract directly a list from another by using ' - ' . [ i for i in list1 if i not in list2]; set(list1) - set(list2) - To repeat each element of lists, [i for i in list for _ in range(int)] - list_1 += list_2 equal to list_1 = list_1 + list_2 Examples
|
Common Functions
- step 1 by default; stop at n-1 even if negative index- create a new list. lst2 = lst1 creates a reference to the original list with the same ID- cannot combine a list containing only number (int & float). [str(i) for i in list]- If there're duplicated elements, it remove only the first element- stop could be higher than start with a negative step |
Cheatography
https://cheatography.com
Python_Chap_4 Cheat Sheet by Theo666
lists : a collection of items that are ordered and mutable
Created By
Metadata
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets
More Cheat Sheets by Theo666