Perl Christmas Quiz

Avleen Vig avleen at gmail.com
Tue Dec 16 14:12:26 GMT 2008


On Tue, Dec 16, 2008 at 11:35 AM, Paul Makepeace <paulm at paulm.com> wrote:
>> Yes, but can Python do it in one line?
>
> [(i,) * min(l1.count(i), l2.count(i)) for i in set(l1).intersection(set(l2))]
>
> That produces an array of tuples of the repeated elements,
>
> [('q',), ('p', 'p'), ('n',)]
>
> A truly flat list is left as exercise (I battle with a reduce+lambda
> hack but didn't quite win.)

I'm probably misunderstanding 'truly flat' but like this?
[''.join(i) * min(l1.count(i), l2.count(i)) for i in
set(l1).intersection(set(l2))]]


More information about the london.pm mailing list