I just started using python and I am trying to initialize two lists using list comprehensions. Like this
list1 = list2 = [0.0] * 57
When i do this and insert these lists with values i am getting a different set of values (incorrect values) when compared to the values i get when i initialize these lists seperately. Like
list1 = [0.0] * 57
list2 = [0.0] * 57
What is happening in the first case ? Why am I getting different answers for these 2 cases ?
The first one sets list1 and list2 to both refer to the same list. The second one defines a new list for each name.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With