Home > database >  How to iterate a list in a loop
How to iterate a list in a loop

Time:11-02

The code worked properly if I added unique values in the param1 dict. However, I want to iterate three dicts instead of three specifical values. How can I handle this problem?

param1 ={ "create_time": "2021-09-01 10:14:27",
         "current_head_coal_feedback_value":12.09,
        "current_head_coal_set_value":12 }  

def column0(mat,i):
    return[row[0]for row in mat]

def column1(mat,i):
    return[row[1]for row in mat]

def column2(mat,i):
    return[row[2]for row in mat]     

param1 ={ "create_time": "column0(params_list,0)",
          "current_head_coal_feedback_value":column1(params_list,0),
          "current_head_coal_set_value":12}    

CodePudding user response:

not sure if this is what you are asking but you get all the column keys in an array

columns = []
for key, value in param1.items():
    columns.append(value)
print(columns)

CodePudding user response:

list1 = [1, 11, 111]
list2 = [2, 22, 222]
list3 = [3, 33, 333]
collection = [list1, list2, list3]
def lists():
    for list in collection:
        return(list)

Hopefully this way works!

  • Related