简体   繁体   中英

Print lists in list

I want to print list in a list using for loop, what i am doing is:

k = "/BTC"
for i in range(l):
    if k in dat1["Data"][i]['Label']:
    value = dat1["Data"][i]['Label']
    value1 = dat1["Data"][i]['TradePairId']
    value2 = dat1["Data"][i]['AskPrice']
    value3 = dat1["Data"][i]['BidPrice']
    li1 = [value, value1, value2, value3]
    list = [li1+1 for g in li1]
    print(float(list))

on every iteration 'li1' has some values, i want to make a new list that should store the data of 'li1' into an index on every iteration, and then print the whole list in the end. Thanks in advance

Not sure what you mean with "store the data of 'li1' into an index". I'm assuming you want a list of lists? You could append the list.

k = "/BTC"
result_list = []
for i in range(l):
    if k in dat1["Data"][i]['Label']:
        value = dat1["Data"][i]['Label']
        value1 = dat1["Data"][i]['TradePairId']
        value2 = dat1["Data"][i]['AskPrice']
        value3 = dat1["Data"][i]['BidPrice']
        result_list.append([value, value1, value2, value3])
print(result_list)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM