[Tutor] I can't believe this needs to be this complex
Dick Moores
rdm at rcblue.com
Sat Aug 2 13:18:09 CEST 2008
At 03:49 AM 8/2/2008, Dick Moores wrote:
>At 03:27 AM 8/2/2008, Andre Engels wrote:
>>Content-Transfer-Encoding:
>>base64Content-Disposition: inlineOn Sat, Aug 2,
>>2008 at 11:07 AM, Dick Moores <rdm at rcblue.com> wrote:
>> > I'm pretty new to Python's dictionaries, but I had a need for a function
>> > that would find the values in a dict that have more than one key each. It
>> > took me several hours to write. See
>> >
>> <http://py77.python.pastebin.com/f397582d8ˆÙY[\ÈÈÈH›Ø‹›ÝÚ]ˆHexample
>> shown, and with the dict of colors at>
>> <http://py77.python.pastebin.com/f796752ff>.
>> >
>>]HØ[‰Ý™[Y at ve the function needs to be so complex. And also, I suppose
>> > I've reinvented the wheel (again). Please instruct me.
>> >
>>^H\ÛÙÚY\È[ˆY˜[˜ÙHÈÙ[›Üˆ›Ý\Ú[™ÈHÚ@ngle list comprehension.
>>
>>Well, list comprehension does indeed seem the solution to your
>>problem, although a single list comprehension would not be necessary.
>>I came to http://py77.python.pastebin.com/m4dcbb34f (note: this is
>>untested, I have no Python on the computer I am working on now), or
>>http://py77.python.pastebin.com/f76ba5002 to indeed just use a single
>>list comprehension (or rather, two nested list comprehensions, again
>>untested for the above reason).
>
>You genius! How could you answer so quickly and
>accurately (20 minutes!) without access to Python?
>
>Both of your scripts work, after I corrected one
>typo. See <http://py77.python.pastebin.com/f7b6e51e8>.
And here's your one-liner
(<http://py77.python.pastebin.com/f789096e9>) at
work on the dict of colors at <http://py77.python.pastebin.com/f796752ff>.
Dick
More information about the Tutor
mailing list