Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Add element on List + Showing the index of this List

list1 = [10, 20, [300, 400, [5000, 6000], 500], 30, 40] 
  1. i’ve needed to add element "7000" after the [6000]

  2. also how to show the index of the value of 40

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading