Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Map to add 1 to each value in a list
- ls = [34, 6, 8, 2, 1, 5]
- lst =['bobbby ', ' tim',' Susan ']
- list(map(lambda x: x + 1, ls))
- #Map to make all numbers in a list positive
- list(map(lambda x: abs(x), ls))
- #or
- list(map(lambda x: -x if x < 0 else x, ls))
- #Map to remove whitespace from all strings in a list
- list(map(lambda x: x.strip(),lst))
- #Map to transform a dictionary into Key-Value pairs
- d = {4:'Frank', 9:'Ada', 32:'Sue'}
- list(map(lambda k: (k, d[k]), d))
- #Reduce function
- def mycount(i):
- count = 0
- for x in i:
- count += 1
- return count
- #mycount(range(4))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement