Useful functions [mapping(with code and by inbuild function) , zip and filter.]

 ##maping:-[1,2,3,4,5] :-[1,4,9,16,25]

 ##firstly lets do it by coding, then by inbuild function.

square=[]
numbers=[1,2,3,4,5]
for i in numbers:
z=i*i
square.append(z)
print("square:-"+"with code"+str(square))


print("with function:-"+str(list(map(lambda x:x*x,[1,2,3,4,5]))))


##concatenating two list
list1=[1,2,3,4,5,6]
list2=[7,8,9,10,11]
print(list1+list2)

##combining two lists as a tuple
print(list(zip(list1,list2)))

##filter:-filter elements in a list

print(list(filter(lambda a:a%2==0,[1,2,3,4,5,6,7,8,9,10,11,12,13])))

"C:\Users\darul Haram\PycharmProjects\pythonProject2\venv\Scripts\python.exe" "C:/Users/darul Haram/PycharmProjects/pythonProject2/venv/Lib/Useful Functions.py"
square:-with code[1, 4, 9, 16, 25]
with function:-[1, 4, 9, 16, 25]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
[(1, 7), (2, 8), (3, 9), (4, 10), (5, 11)]
[2, 4, 6, 8, 10, 12]

Process finished with exit code 0

Comments

Popular posts from this blog

XAMPP, SQL BASIC COMMANDS

The Minion Game Hackerrank Solution

Arrays - DS | HackerRank Solutions