any one can write code for the above tittle
how to get a index of items in list view
Collapse
X
-
Tags: None
-
Can you give an example of what you're looking for? As I understand it the "index" relates to the position of elements in a "list", so "index of items in list view" is a little confusing (to me). Do you by chance want to print out each item in some sequence data? -
Originally posted by vivekajain12345 6789any one can write code for the above tittle
Code:s = [1,2,3,4,1,2,3,4,1,2,4,3,4,5,6,6,7,8,9,1,2,3,4,5,6,7,3,2,1] def get_index(s, item): i = 0 i_list = [] while True: try: i = s.index(item, i) i_list.append(i) i += 1 except: break return i_list print get_index(s, 1) print get_index(s, 4) print get_index(s, 7) print get_index(s, 0) >>> [0, 4, 8, 19, 28] [3, 7, 10, 12, 22] [16, 25] [] >>>
Comment
Comment