Selecting elements from a list

Martin Christensen knightsofspamalot-factotum at gvdnet.dk
Fri Sep 5 02:18:27 EDT 2003


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

>>>>> "Duncan" == Duncan Smith <buzzard at urubu.freeserve.co.uk> writes:
Duncan> Is this the sort of thing you mean?

Duncan> >>> A = [0, 1, 2, 'four', 'five', 6.0]
Duncan> >>> [x for x in A if isinstance(x, str)]
Duncan> ['four', 'five']
Duncan> >>>

Yes, that's exactly the sort of thing I meant. For some reason, I have
built some intuition of list comprehensions as always being one to
one. Now, the one place I should have looked that I didn't was the
Python tutorial, which I thought I was done with by now. The clarity
of hindsight is a bitch. :-) Thanks.

Martin

- -- 
Homepage:       http://www.cs.auc.dk/~factotum/
GPG public key: http://www.cs.auc.dk/~factotum/gpgkey.txt
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)
Comment: Using Mailcrypt+GnuPG <http://www.gnupg.org>

iEYEARECAAYFAj9YKrMACgkQYu1fMmOQldX6kACglqJBUiFL4gGrRmDgchZYEm53
vWQAnRxm7YzaGSlhIRtLd29zwlCmplDA
=7NNS
-----END PGP SIGNATURE-----




More information about the Python-list mailing list