0

Here is my code :

list1  = [{'price': '21213.50', 'symbol': 'BTCUSD', 'id': 212135000, 'side': 'Sell', 'size': 24218}]
list2 = [{'price': '21213.50', 'symbol': 'BTCUSD', 'id': 212135000, 'side': 'Sell', 'size': 12788}]
list3 = [{'price': '21213.50', 'symbol': 'BTCUSD', 'id': 212135000, 'side': 'Sell', 'size': 7358}]
list4 =[{'price': '21221.50', 'symbol': 'BTCUSD', 'id': 212215000, 'side': 'Sell', 'size': 16817}, {'price': '21213.50', 'symbol': 'BTCUSD', 'id': 212220000, 'side': 'Sell', 'size': 60657}]

As you can see I have 4 list or more it doesn't matter. First I defined a function to convert these list into dicts.

def list_to_dict(a):
    for i in range(len(a)):
        print(a[i])

when I call this function like :

list_to_dict(list1)
list_to_dict(list2)
list_to_dict(list3)
list_to_dict(list4)

I get these results :

{'price': '21213.50', 'symbol': 'BTCUSD', 'id': 212135000, 'side': 'Sell', 'size': 24218}
{'price': '21213.50', 'symbol': 'BTCUSD', 'id': 212135000, 'side': 'Sell', 'size': 12788}
{'price': '21213.50', 'symbol': 'BTCUSD', 'id': 212135000, 'side': 'Sell', 'size': 7358}
{'price': '21221.50', 'symbol': 'BTCUSD', 'id': 212215000, 'side': 'Sell', 'size': 16817}
{'price': '21213.50', 'symbol': 'BTCUSD', 'id': 212220000, 'side': 'Sell', 'size': 60657}

after that I want to compare these dicts, I am trying to achieve these result( both dictionaries price and side are equal but size is different) by different I want how different ? for ex. size increased by 10000 as integer. Target output = a tuple maybe for ex. (21213.5,sell) increased by 10000.

Matt Pitkin
  • 3,989
  • 1
  • 18
  • 32
  • "First I defined a function to convert these list into dicts." It **does not do this**, and it will be impossible to write any more useful code without understanding and fixing that problem. Please read the linked duplicates in order to understand. In order to process all the dictionaries with the same code, put them into **one** list, by joining the existing lists together (first duplicate). The second duplicate explains why the `list_to_dict` function is completely useless for further processing; it **only displays** some information, and **does not provide** it to the rest of the program. – Karl Knechtel Jan 17 '23 at 14:16
  • After that point, however, there is no clear question here. "Compare" **does not mean anything** by itself. In order to write code, we must have a **rule that tells us, what should happen** according to the the differences between what is compared. – Karl Knechtel Jan 17 '23 at 14:17
  • my function breaks list with index numbers so I know it doesn't convert a list to dictionary , but it converts list of dicts to one by one. I looked up duplicates but couldnt find the solution. – Ali Sarikaya Jan 17 '23 at 14:19
  • "but it converts list of dicts to one by one." No, it does not. It does not do any kind of conversion. It **displays the contents** of the lists. "I looked up duplicates but couldnt find the solution." That's why I already explained to you what to do (join the `list1`, `list2` etc. into one list) and directly pointed at a duplicate that explains how to do that. – Karl Knechtel Jan 17 '23 at 14:33
  • I am not trying to combine all lists. I already parsed a large list to small ones for achieving my target . But seems you didnt read it through. – Ali Sarikaya Jan 17 '23 at 14:51
  • I am **explaining to you** that combining the lists **is necessary** to do the rest of what you want to do in any reasonable way, and that the existing `list_to_dict` function **does not and cannot possibly** help with that part. However, I cannot any more advice than that, because "the rest of what you want to do" is too vague. – Karl Knechtel Jan 17 '23 at 14:54

0 Answers0