Answers for "how to create a map in python"

0

use map in python to take input

c = map(int,input().split)
Posted by: Guest on July-05-2020
2

map in python

# Python program to demonstrate working 
# of map. 
  
# Return double of n 
def addition(n): 
    return n + n 
  
# We double all numbers using map() 
numbers = (1, 2, 3, 4) 
result = map(addition, numbers) 
print(list(result))
# result [2, 4, 6, 8]
Posted by: Guest on June-05-2020
1

map function in python

# for the map function we give a function (action to act), a data action to act on that data.

# without map
def multiply_by2(li):
    new_list = []
    for number in li:
        new_list.append(number*2)
    return new_list


print(multiply_by2([1, 2, 3]))


# using map function
def multiply_by_2(item):
    return item*2


print(list(map(multiply_by_2, [1, 2, 3])))

# function that returns usernames in all uppercase letters.
usernames = ["RN_Tejas", "RN_Tejasprogrammer", "Rajendra Naik", "yooo", "Brainnnni", "Ouuuuut"]


def no_lower(item):
    return item.upper()


print(list(map(no_lower, usernames)))

# squares function
list_squares = list(range(1, 101))
print(list_squares)


def square(number):
    return number**2


square_list = list(map(square, list_squares))


def square_root(number):
    return number // number


print(list(map(square_root, square_list)))


def no_upper(string):
    return string.lower()


print(list(map(no_upper, 'TEJAS')))
Posted by: Guest on December-31-2020
-1

map in python

>>> numbers = [1, 2, 3, 4, 5]
>>> squared = []

>>> for num in numbers:
...     squared.append(num ** 2)
...

>>> squared
[1, 4, 9, 16, 25]
Posted by: Guest on April-12-2021

Code answers related to "how to create a map in python"

Python Answers by Framework

Browse Popular Code Answers by Language