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

Python Long List

I want to find the number of the object and the object near that from a large python list like this:

list = ['askdjh', 'afgld', 'asf' ,'asd', '623gfash', 'fhd', 'hfdjs']

And I chose ‘asd’ :

number = 4
item near it = 623gfash

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

pos = my_list.index('asd')
nearest = my_list[pos + 1]

Note pos is 3 for the 4th element as Python is 0- based. Note avoid using list for variables as this name has a special meaning in Python.

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