-2

How could i get the same result with a map? i'm a beginner trying to learn how maps relate to iteration. Is it possible to put this loop into a map?

user_list = [int(input("what is the fist integer? "))]

for i in user_list:
    if i < 100:
        i *= 2
    if i > 100:
        break
    user_list.append(i)
qjrob
  • 1

1 Answers1

-1

I am not quite sure if you are looking for the "map" function or for an actual "map" data type.

if you are looking for how to use the "map" function of python then you can just use it like this:

map(function,iterable)

The function will run for each element in the iterable.

In the "function" place you can place your function or use a lambda expression, something like:

x = map(lambda y: y*2 if y < 100 else None, [5,10,20])

in order to print that you will again have to convert it to a list if i remember correctly:

print(list(x))

if you are looking for a "map" like data type in python you can lookup "dictionaries"

Aru
  • 352
  • 1
  • 11