[Tutor] if in an iteration, quick Q!!
Kent Johnson
kent37 at tds.net
Tue May 1 12:18:08 CEST 2007
John Washakie wrote:
> I can't recall how to do this:
>
> I want:
> a = [int(x) for x in tmp]
>
> but, my tmp has some empty elements, so it fails...
>
> Therefore I want to be able to say:
>
> a = [int(x) for x in tmp IF x in tmp]
That's almost right, except it checks the wrong thing. Try
a = [int(x) for x in tmp if x]
Depending on what an 'empty' element is you may have to refine that.
Kent
More information about the Tutor
mailing list