[Tutor] indexing elements

Ian Witham witham.ian at gmail.com
Tue Sep 4 04:53:36 CEST 2007


Hi,

I'm not too sure what your asking here,

your code assigns the following to endings:
['st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th',
'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'st', 'nd', 'rd', 'th',
'th', 'th', 'th', 'th', 'th', 'th', 'st']

This is what we would expect.. 17 * ['th'] causes 17 repetitions of 'th' in
the list.
certain operators, like the multiplication operator in your example, have
additional behavior depending on what kind of data they are applied to.

The repetition operator binds closer than the '+' as the following brackets
show.

endings = ['st', 'nd', 'rd'] + (17 * ['th']) + ['st', 'nd', 'rd'] + (7 *
['th']) + ['st']

Ian.

On 9/4/07, chinni <srikanth007m at gmail.com> wrote:
>
> Hi all,
>
> i had some doubt about this line  can any body clarify this plz.......
> endings = ['st', 'nd', 'rd'] + 17 * ['th'] + ['st', 'nd', 'rd'] + 7 *
> ['th'] + ['st']
>
> --
> Best Regards,
> M.Srikanth Kumar,
> Jr.Software Developer,
> Google India Pvt Ltd..,
> HYDERABAD.
> Phone no: +91-9866774007
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070904/01920139/attachment.htm 


More information about the Tutor mailing list