To assign one list to another in python, you can simply use the assignment operator. Here's an example:
main.py92 chars4 lines
In this example, alist is assigned the list [1, 2, 3, 4]. Then, blist is assigned alist, so blist refers to the same list object as alist.
If you modify the original list (in this case, alist), the changes will also be reflected in the new list (in this case, blist):
main.py48 chars3 lines
In this example, 5 is appended to alist, which also modifies blist. Now, blist is [1, 2, 3, 4, 5].
If you want to create a copy of the original list, you can use the copy() method or slice notation:
main.py115 chars3 lines
Both clist and dlist will refer to a new list object that has the same elements as alist.
gistlibby LogSnag