[Tutor] Sorting/filtering data, dictionary question & Re:OT

Bill Burns billburns at pennswoods.net
Wed Jan 5 01:00:53 CET 2005


On Monday 03 January 2005 11:09 pm, Jacob S. wrote:
> You're thinking right. The syntax is supposed to be something like
>
> [ altereditem for item in iterable if condition ]
>
> So,
> to get all the even numbers between 1 & 10
>
> >>> a = [x for x in range(1,11) if x % 2 == 0]
> >>> print a
>
> [2,4,6,8,10]
>
> For a much, much better explanation, I recommend Alan Gauld's tutorial, the
> section which is relevant can be found here
> http://www.freenetpages.co.uk/hp/alan.gauld/tutfctnl.htm
>

Jacob,

Thank you for the information & link, I'll definitely check it out.

Bill



More information about the Tutor mailing list