M
Manuel Graune
Hello,
in (most) python documentation the syntax "list()"
and "[]" is treated as being more or less the same
thing. For example "help([])" and "help(list())" point
to the same documentation. Since there are at least
two cases where this similarity is not the case, (see below)
can someone explain the reasoning behind this and point to
further / relevant documentation?
(To clarify: I am not complaining about this, just asking.)
1.)
when using local variables in list comprehensions, say
a=[i for i in xrange(10)]
the local variable is not destroyed afterwards:
print "a",a
print "i",i
using the similar code
b=list(j for j in xrange(10))
the local variable is destroyed after use:
print "b",b
print "j",j
and 2)
a=list([])
vs.
b=[[]]
Regards,
Manuel Graune
in (most) python documentation the syntax "list()"
and "[]" is treated as being more or less the same
thing. For example "help([])" and "help(list())" point
to the same documentation. Since there are at least
two cases where this similarity is not the case, (see below)
can someone explain the reasoning behind this and point to
further / relevant documentation?
(To clarify: I am not complaining about this, just asking.)
1.)
when using local variables in list comprehensions, say
a=[i for i in xrange(10)]
the local variable is not destroyed afterwards:
print "a",a
print "i",i
using the similar code
b=list(j for j in xrange(10))
the local variable is destroyed after use:
print "b",b
print "j",j
and 2)
a=list([])
vs.
b=[[]]
Regards,
Manuel Graune