Map concept in python

numbers=["23""32""30""54"]


# normal method to do this
# for index,items in enumerate(numbers):
    # numbers[index] = int(numbers[index])


# second and easy method to perform one function to all of the list at once....
numbers = list(map(int,numbers))
numbers[2= numbers[2+ 3
print(numbers)

# one more example 
def squre():
    num=[]
    i=0
    row=int(input("How many numbers you want to enter: "))
    try:
        while i<row:
            if i == 0:
                get = int(input("Enter the number: "))
            elif i > 0:
                get = int(input("Enter the next number: "))
            num.append(get)
            i = i + 1

        num = list(map(int, num))
        num = list(map(lambda x: x*x, num))
        print(num)
    except Exception as h:
        print(h)





try:
    b = 0 
    while b ==0:
        ans = input("Enter yes to continue or no to exit(): ")
        if ans == str("yes"):
            squre()
        elif ans == str("no"):
            print("ok gud bye sir....")
        b = b  + 1



    
except Exception as e:
    print(e)

# print("Gudbye sir I've do you work: ")

# Map() function
# (map) = applies a function to each item in an iterable ( list, tuple, etc)
# syntax = map(function, iterable)
 

store = [("shirt"30.00),
         ("pants"153.33),
         ("jacket"23.4),
         ("socks"10.00)]
def to_repees(data): return (data[0], data[1]/150)
store_repees = list(map(to_repees, store))
for i in store_repees:
    print(i)

Comments