W W a écrit : > On Sat, Nov 22, 2008 at 9:42 AM, spir <[EMAIL PROTECTED]> 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. denis _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor