Backdrop
While fiddling with the map()
function in my Python project, I tried to assign a variable, the python map object I intended to create once, and then reuse the same map object to use them as strings, lists or tuples, etc.
Brief reproduction of the problem:
def concat(n):
return n + "abc"
def upp(Lst):
for i in Lst:
if i[0].isupper():
return i
def low(Lst):
for i in Lst:
if i[0].islower():
return i
#main
L = ["a","B","c"]
m = map(concat,L) #Creating a Python map object
print(f"Capitalised string: {upp(list(m))} lowercased string: {low(list(m))}") #Accessing the returned manipulated map object
Expected Output:
Capitalised string: Babc lowercased string: aabc
Problem:
Actual output:
Capitalised string: Babc lowercased string: None
#Manual Debugging:
u = upp(list(m))
l = low(list(m))
print(u,l)
Output:
["aabc","Babc","cabc"][]
So as you can see, the second time I try to retrieve the map object, it doesn't return anything in the list.
Final Question:
I want to know why is it so that the map object is not accessible even when it does exist.
Note:
The following questions don't answer my question:
Map function not returning a value because:
I. Not related to
Python
map object.II. There the map object does return some value but it isn't being used properly.
map function isnt returning the values because:
I. Not related to Python
II. The map function object does return some value there.
Python - Printing Map Object Issue because:
I. Much related to my question but still has not proper/relevant references/citations to materials explaining the reason(s) of it being treated as a consumable object.
Python: casting map object to list makes map object empty? because:
I. Not enough citations to documentations clearly stating the fact.
Edits which improve the sample program which reproduces the problem will be welcomed.