[Tutor] split struggle

Richard D. Moores rdmoores at gmail.com
Wed Jun 23 04:16:59 CEST 2010


On Tue, Jun 22, 2010 at 15:09, Alan Gauld <alan.gauld at btinternet.com> wrote:
>
> "Richard D. Moores" <rdmoores at gmail.com> wrote
>
>> This does what I want, which is to do one of:
>> 1. print all the elements of the list, lst.
>> 2. print "Done" when "" is entered.
>> 3. print the elements of lst whose indexes are entered.
>> (sorry if all this is obvious)
>>
>> Now, the code works, but isn't there a better way to do what I want?
>> I've been away from Python for a while, and have gotten rusty.
>
> Its pretty straightforward, I'm not sure what you are thinking of
> to simplify/improve it.
>
> The only change I'd make is the last else:
>
>> indexes = [int(k) for k in indexes]
>
> You don't need the list comp
>
>>   print(indexes)
>>   for i in indexes:
>>       print(lst[int(i)])
>
> Will do what you want.
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>


More information about the Tutor mailing list