map returning tuples
numbers = [1, 2, 3, 4]
pairs = map(lambda n: (n, 2*n), numbers)
print(pairs)
for pair in pairs:
print(pair)
Output:
<map object at 0x7fcd264a15f8>
(1, 2)
(2, 4)
(3, 6)
(4, 8)
Press ← or → to navigate between chapters
Press S or / to search in the book
Press ? to show this help
Press Esc to hide this help
numbers = [1, 2, 3, 4]
pairs = map(lambda n: (n, 2*n), numbers)
print(pairs)
for pair in pairs:
print(pair)
Output:
<map object at 0x7fcd264a15f8>
(1, 2)
(2, 4)
(3, 6)
(4, 8)