It's a very simple Python question.

Asked 2 years ago, Updated 2 years ago, 37 views

If there's a list called [1, 2, 3] If each 1, 2, 3, 10, 20, 30, 40, 50, 60, 70, 80, and 90, there's a total of 9 elements in it, so 1: 10,20,30 2: 40,50,60 3: 70, 80.90. Like this.

When you write a for statement and print it out

One is 10, 20, 30 Two is 40, 50, 60 Can we print 3 like 70, 80, 90?

If I write a "for" statement,

1 10 1 20 1 30 2 40 2 50 2 60 3 70 3 80 3 90 In this way, the first 1, 2 and 3 continue to appear for each element. I want 1, 2, 3 to be printed out at first.

list

2022-09-21 10:09

1 Answers

arr = [{'a': [1, 2, 3]}, {'b': [4, 5, 6]}, {'c': [7, 8, 9]}]
for value in arr:
    print(*value.keys(), *value.values())
# # a [1, 2, 3]
# # b [4, 5, 6]
# # c [7, 8, 9]


2022-09-21 10:09

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.