Created
November 9, 2017 19:47
-
-
Save RodolfoFerro/161ae8fd91ed1d8f1e8ae28648d4540d to your computer and use it in GitHub Desktop.
Gist to illustrate the insertion of first element on nested list.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Import copy lib | |
import copy | |
# Create lists: | |
names = ["Mary", "David", "George"] | |
numbers = [[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6]] | |
# Create a deep copy to avoid using same memory direction: | |
new_list = copy.deepcopy(numbers) | |
# Insert elements as wanted: | |
for i in new_list: | |
i.insert(0, names[0]) | |
# Print (the one edited) new list: | |
print(new_list) | |
# We can compare with the original list: | |
print(numbers) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment