0.2 List
Methods
Copy
- copy all
new_list = old_list[:]
new_list = list(old_list)
- copy some
lst1[i:j] = list2[i:j]
Reverse
reverse a list, in place
lst[:] = lst[::-1]
or
lst.reverse()
reverse a sublist, in place:
lst[i:j] = lst[i:j:-1]
Zip
- zip a list itself to make list of tuples like [(lst[i], lst[i+1]),(lst[i+1], lst[i+2]), ...]
zip(lst, lst[1:]),
- zip two lists:
zip(lst1, lst2)