[Tutor] efficient method to search between two lists

Smith smiles at worksmail.net
Fri Mar 24 16:21:25 CET 2006

Srinivas Iyyer wrote:
|||| for i in list_b:
| ...         co = i.split('\t')[2]
| ...         items = da.get(co)
Are you sure that all co's are in da?

One other thing that occurs to me from looking at your dictionary approach is that if you made a dictionary from the items of list_b like you did for list_a and then made a set of the keys from the union of both dictionaries and used that set (rather than co as above) to retrieve matches, this would automatically ensure that the match existed and it would group like items together. Right now (unless your list_b is sorted) you might encounter an item in list_b that has a match in da several times as you pass through list_b.


More information about the Tutor mailing list