[Tutor] the sense of brackets

W W srilyk at gmail.com
Sat Nov 22 20:17:38 CET 2008


On Sat, Nov 22, 2008 at 9:42 AM, spir <denis.spir at free.fr> wrote:

> I have long thought "[]" /simply/ is a list constructor syntax.
> What do you think of the following?
>
> t = "aze"
> print t, list(t), [t]
> print list(list(t)), list([t]), [list(t)], [[t]]
> ==>
> aze ['a', 'z', 'e'] ['aze']
> ['a', 'z', 'e'] ['aze'] [['a', 'z', 'e']] [['aze']]

Consider the following:
In [1]: list("Hello")
Out [1]: ['H', 'e', 'l', 'l', 'e', 'o']
and the list docstring:
list() -> new list
list(sequence) -> new list initialized from sequence's items
so list(list(t)) makes perfect sense: list(t) is ['a', 'z' ,'e'] and
list(list(t)) simply creates a new list initialized from that list's items
HTH,
Wayne
-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn't. - Primo Levi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081122/4ef03692/attachment-0001.htm>


More information about the Tutor mailing list