Lipat gandakan setiap elemen dalam daftar python
a_list = [1, 2, 3]
multiplied_list = [element * 2 for element in a_list]
# [2, 4, 6]
Marton
a_list = [1, 2, 3]
multiplied_list = [element * 2 for element in a_list]
# [2, 4, 6]
c_list = [[5, 6, 8], [7,3], [8, 10, 12]]
d_list = c_list[:]
for i in range(len(c_list)):
for j in range(len(c_list[i])):
d_list[i][j] = c_list[i][j] * 2
print(d_list)
# [[10, 12, 16], [14, 6], [16, 20, 24]]