Bài tập List Comprehension - Nâng cao
Bài tập về List Comprehension - Nâng cao
matrix = # Code của bạn ở đây
print(matrix)
# Kết quả: [[1, 2, 3], [4, 5, 6], [7, 8, 9]]matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
flattened = # Code của bạn ở đây
print(flattened)
# Kết quả: [1, 2, 3, 4, 5, 6, 7, 8, 9]identity = # Code của bạn ở đây
print(identity)
# Kết quả: [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]words = ["hello", "world", "python", "programming"]
word_lengths = # Code của bạn ở đây (dùng dict comprehension)
print(word_lengths)
# Kết quả: {'hello': 5, 'world': 5, 'python': 6, 'programming': 11}Last updated