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

>Solution :


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.

Leave a Reply