InterviewSolution
Saved Bookmarks
| 1. |
Comprehensions in Python |
Answer»
# b will store values which are 1 greater than the values stored in a b = [i + 1 for i in a] print(b) Output: [1, 2, 3, 4]
# b will store squares of the elements of a b = {i ** 2 for i in a} print(b) Output: {0, 1, 4, 9}
# b stores elements of a in value-key pair format b = {val: k for k , val in a.items()} print(b) Output: {'World': 'Hello', 1: 'First'} |
|