[Tutor] the sense of brackets
Lie Ryan
lie.1296 at gmail.com
Mon Nov 24 12:04:14 CET 2008
On Sat, 22 Nov 2008 22:58:48 +0100, spir wrote:
> W W a écrit :
> > 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
>
> Yep! What surprises me is the behaviour of [] instead. I can understand
> that list(t) != [t]
> but
> [list(t)], [[t]] --> [['a', 'z', 'e']] [['aze']] is a bit strange to me.
>
what do you expect [] should do on that case? I think it's perfectly
reasonable and consistent with the semantic for [] to just simply
"enclose" whatever inside it with []s instead of converting an iterable
to a list as list() does.
More information about the Tutor
mailing list