Re: list comprehention

2006-01-25 Thread Mathijs
23 jan 2006 ta (Steven D'Aprano) shuo le: >> This is the type of solution I was hoping to see: one-liners, with no >> use of local variables. > > Because you like unreadable, incomprehensible, unmaintainable code? For practical use: no! But I'm just learning python and to understand sets/lists/

Re: list comprehention

2006-01-23 Thread Mathijs
Op 20 jan 2006 vond Duncan Booth <[EMAIL PROTECTED]>: > Or in other words, define a function to return a dictionary containing > a count of the number of occurrences of each element in the list (this > assumes that the list elements are hashable). Then you just add up the > values in the test list

Re: list comprehention

2006-01-23 Thread Mathijs
Op 19 jan 2006 vond "Paddy" <[EMAIL PROTECTED]>: answer = [ val for val in set(ref) for x in range(min(lst.count(val), ref.count(val)))] answer > [2, 2, 4] I don't think it's correct. Your algoritm with the ref and lst below gives 3 as answer. The answer should have been 2 (1,3). ref=

Re: list comprehention

2006-01-23 Thread Mathijs
Op 19 jan 2006 vond Peter Otten <[EMAIL PROTECTED]> : > sum(min(list.count(n), ref.count(n)) for n in set(ref)) > > Is that it? Seems like this is it! Thanks. -- http://mail.python.org/mailman/listinfo/python-list

Re: list comprehention

2006-01-23 Thread Mathijs
Op 19 jan 2006 vond "[EMAIL PROTECTED]" : > another approach: > > ref = [2,2,4,1,1] > lis = [2,2,5,2,4] > > len([ref.pop(ref.index(x)) for x in lis if x in ref]) > This is the type of solution I was hoping to see: one-liners, with no use of local variables. As Tim Chase already wrote, it has

list comprehention

2006-01-19 Thread Mathijs
Hi, Python beginner here and very much enjoying it. I'm looking for a pythonic way to find how many listmembers are also present in a reference list. Don't count duplicates (eg. if you already found a matching member in the ref list, you can't use the ref member anymore). Example1: ref=[2, 2,