Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # map_list_introduction.py
- #other ways of mapping also shown
- def double(n):
- return n*2
- li1=[1,2,3,4,5,6]
- li2=['a','b','c','d','e']
- mapped_list1= map(double,li1)
- mapped_list2= map(double,li2)
- print mapped_list1
- print mapped_list2
- # one line map code
- ml1=map(lambda x: x*2,li1)
- ml2=map(lambda x: x*2,li1)
- print ml1
- print ml2
- # map by list comprehension
- nl1=[i*2 for i in li1]
- nl2=[i*2 for i in li2]
- print nl1
- print nl2
- # map by for loop
- newlist1=[]
- newlist2=[]
- for i in li1:
- newlist1.append(double(i))
- for i in li2:
- newlist2.append(double(i))
- print newlist1
- print newlist2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement