Thursday 15 July 2010

python - Lookups in lists / set and modification of elements -



python - Lookups in lists / set and modification of elements -

i have created function finds if items within lists mutual , if modify specific elements within lists(lists nested). problem lookups within list o(n). if have huge lists spend much time on lookups. here function using lists:

def union_finder(list_of_lists_unions): while list_of_lists_unions: processed_list = list_of_lists_unions.pop(0) item in processed_list: loc_list,pointer_list in enumerate(list_of_lists_unions): location,iteration in enumerate(pointer_list): if item == iteration: #if status alter element matches on lists if(something): count +=1 index_dict[item] = count list_of_lists_unions[loc_list][location] = str(index_dict[item]) + str('@')

the function works perfectly. illustration if set input this:

[[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30], [1, 2, 3, 4, 29, 30], [100, 200, 300, 28, 29, 30]]

edit

i trying utilize set(), because lookup complexity o(1) (as documentation says). thing using lists can modify elements within iterations. sets don't allow me modify specific elements within them. thought locate items want within set, cast list create modifications want , recast set. efficient ? there other way utilize set's lookup speed? list's complexity lookups o(n) much because lists somethimes pretty long , if seek compare 2 lists len(list1) = m, len(list2) = n , m*n lookups (x in s).

python list set lookup nested-lists

No comments:

Post a Comment