Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Does "map" destroy its input?

I write the following in the SageMath cloud:

Bob="xyz"
sB = subsets(Bob)
print map(str, sB)
print map(str, sB)

and the output is:

['[]', "['x']", "['y']", "['x', 'y']", "['z']", "['x', 'z']", "['y', 'z']", "['x', 'y', 'z']"]
[]

I.e, after the first "map", the variable "sB" becomes empty!

Why does this happen?

click to hide/show revision 2
retagged

Does "map" destroy its input?

I write the following in the SageMath cloud:

Bob="xyz"
sB = subsets(Bob)
print map(str, sB)
print map(str, sB)

and the output is:

['[]', "['x']", "['y']", "['x', 'y']", "['z']", "['x', 'z']", "['y', 'z']", "['x', 'y', 'z']"]
[]

I.e, after the first "map", the variable "sB" becomes empty!

Why does this happen?