list_a-list_b

Michael Gilfix mgilfix at eecs.tufts.edu
Wed Apr 17 02:13:39 EDT 2002


  I didn't make any promise of efficiency :) It was more of a way to
clarify the iteration someone else suggested. One nice thing about
using filter though and the implied iteration is that it becomes
much simpler to make comparisions of compound objects. I've become
a big fan of things like 'map' and 'filter', etc... I find they
often express a very elegant solution (not necessarily the most
efficient but since they are built-in functions - can they perform any
optimization?). Perhaps I just like functional environments. The sort
of comprehension primitives you liked from lisp but not using lisp.

                 -- Mike

On Wed, Apr 17 @ 01:54, Tim Peters wrote:
> [David Eppstein]
> > ...
> > Better is to convert b to a dictionary
> > (where are dict comprehensions when you need them):
> >
> >     dict_b = {}
> >     for x in list_b: dict_b[x] = 1
> 
> Looks clear enough to me, although
> 
>     for x in list_b:
>         dict_b[x] = 1
> 
> is clearer.  If you like, you can do this:
> 
>     dict([(x, 1) for x in list_b])
> 
> or this:
> 
>     dict(zip(list_b, [1]*len(list_b)))
> 
> or even:
> 
>     dict(zip(list_b, list_b))
> 
> since you don't really care what the dict's values are, just the keys.  I
> draw the line before:
> 
>     dict(zip(*[list_b]*2))
> 
> though.  Contrary to popular belief, there's no Fabulous Prize awaiting
> those who minimize either vertical or horizontal space <wink>.
> 
> 
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
`-> (tim.one)

-- 
Michael Gilfix
mgilfix at eecs.tufts.edu

For my gpg public key:
http://www.eecs.tufts.edu/~mgilfix/contact.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 236 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20020417/8fb03d14/attachment.sig>


More information about the Python-list mailing list