If you only have one level, you can just loop through this list and check whether the element is in this list, using the in
keyword.
If, however, you have nested sublists with several levels, you might want to use a recursive function to scan all of them. The function finder()
below scans through all nested lists and returns the indices of the lists in which the element was first encountered:
sublist = [[32,999,15,329,679],
[1738,100,55,1800,1469],
["bruges","manchester","bristol","edinburgh","barcelona"],
["Vienna","Stockholm","Berlin","Prague","Dublin"],
["Dog",["Cat","Parrot"]]]
def finder(nested,element):
for i in range(len(nested)):
if type(nested[i])==list:
f = finder(nested[i],element)
if type(f)==list:
return [i]+f
elif nested[i]==element:
return [i]
print(finder(sublist,"Vienna"))
print(finder(sublist,"Parrot"))
#Output:
#[3, 0]
#[4, 1, 1]
The output means that "Vienna" is in list 3, the 0th element. The element "Parrot" was in list 4, within list 1, the 1th element.