'Add element on List + Showing the index of this List
list1 = [10, 20, [300, 400, [5000, 6000], 500], 30, 40]
i've needed to add element "7000" after the [6000]
also how to show the index of the value of 40
Solution 1:[1]
Use list.insert and list.index
list1 = [10, 20, [300, 400, [5000, 6000], 500], 30, 40]
print(list1)
list1[2][2].insert(2, 7000)
print(list1)
print(list1.index(40))
[10, 20, [300, 400, [5000, 6000], 500], 30, 40]
[10, 20, [300, 400, [5000, 6000, 7000], 500], 30, 40]
4
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | azro |
