Is there a way to use map() function with a string instead of a list? Or the map() function is meant only to work with lists?
For instance, ignoring the content of the lambda function, this code returns a map object and not a string:
def rot_13(string):
alph = 'abcdefghijklmnopqrstuwxyz'
return str(map(lambda i: alph[(alph.find(i)+13) % len(alph)], string))
mapreturns a generator in Python3, try:return "".join(list(map(lambda i: alph[(alph.find(i)+13) % len(alph)], string)))a_list = list(a_string).mapalways returns a map object. No matter the iterable you are napping over. It is meant to work with any iterable.