Re: [Tutor] Re: Unique Items in Lists

2005-01-27 Thread Brian van den Broek
Kent Johnson said unto the world upon 2005-01-27 16:08: Brian van den Broek wrote: Finally, in the first instance, I was aiming for the OP's stated end. To make this more general and reusable, I think I'd do: def get_list_dup_dict(a_list, threshold=1): items_dict, dup_dict = {}, {} # Ques

Re: [Tutor] Re: Unique Items in Lists

2005-01-27 Thread Kent Johnson
Brian van den Broek wrote: incorporating some of Wolfram's and Kent's (hope I've missed no one) suggestions: def dups_in_list_report(a_list): '''Prints a duplication report for a list.''' items_dict = {} for i in a_list: items_dict[i] = items_dict.get(i, 0) + 1 for k, v i

Re: [Tutor] Re: Unique Items in Lists

2005-01-27 Thread Brian van den Broek
Kent Johnson said unto the world upon 2005-01-27 05:57: Brian van den Broek wrote: Wolfram Kraus said unto the world upon 2005-01-27 03:24: This whole part can be rewritten (without sorting, but in Py2.4 you can use sorted() for this) with a list comprehension (Old Python2.1 style, with a newer

Re: [Tutor] Re: Unique Items in Lists

2005-01-27 Thread Kent Johnson
Brian van den Broek wrote: Wolfram Kraus said unto the world upon 2005-01-27 03:24: Brian van den Broek wrote: for key in items_dict.copy(): # Try it without the .copy() if items_dict[key] == 1:# and see what happens. del items_dict[key] dict_keys = items_dict.key

Re: [Tutor] Re: Unique Items in Lists

2005-01-27 Thread Brian van den Broek
Wolfram Kraus said unto the world upon 2005-01-27 03:24: Brian van den Broek wrote: Thanks Wolfram, I knew someone would improve what I posted. (It can always be done ;-) for i in a_list: if i in items_dict: items_dict[i] = items_dict[i] + 1 else: items_

Re: [Tutor] Re: Unique Items in Lists

2005-01-27 Thread Chad Crabtree
Ok you got me thinking. I used the same thing I posted before but created a one liner that as a side affect makes adict like before. [adict.__setitem__(x,adict.get(x,0)+1) for x in l] I think it's kinda funny and ugly, ohh and not particuarly clear about what it does. Wolfram Kraus wrote: > g