Code Explanation:
1. Creating a list
chars = ['a', 'b', 'c']
This line creates a list named chars.
The list contains three characters: 'a', 'b', and 'c'.
2. Using map()
m = map(ord, chars)
map() applies a function to each item in an iterable.
Here:
ord is a built-in function that converts a character to its Unicode (ASCII) value.
chars is the iterable.
map() does not execute immediately.
It returns a map object (an iterator), stored in m.
3. Converting the result to a list
print(list(m))
list(m) forces the map object to execute.
ord() is applied to each character:
ord('a') → 97
ord('b') → 98
ord('c') → 99
The results are collected into a list and printed.
✅ Final Output
[97, 98, 99]

0 Comments:
Post a Comment