Skip to content

Instantly share code, notes, and snippets.

@JosephTLyons
Created February 10, 2022 05:39
Show Gist options
  • Save JosephTLyons/a92e8efef6af4884e39f74223285f7e5 to your computer and use it in GitHub Desktop.
Save JosephTLyons/a92e8efef6af4884e39f74223285f7e5 to your computer and use it in GitHub Desktop.
Helped a friend write some code...
from collections import defaultdict
currency_combo_strings = ["btcusd","btcgusd","btcdai","btcgbp","btceur","btcsgd","ethbtc","ethusd","ethgusd","ethgbp","etheur","ethsgd","ethdai","bchusd","bchbtc","bcheth","ltcusd","ltcbtc","ltceth","ltcbch","zecusd","zecbtc","zeceth","zecbch","zecltc","batusd","batbtc","bateth","linkusd","linkbtc","linketh","daiusd","oxtusd","oxtbtc","oxteth","filusd","ampusd","paxgusd","compusd","mkrusd","zrxusd","kncusd","storjusd","manausd","aaveusd","snxusd","yfiusd","umausd","balusd","crvusd","renusd","uniusd","enjusd","bntusd","1inchusd","sklusd","grtusd","lrcusd","sandusd","cubeusd","lptusd","bondusd","maticusd","injusd","sushiusd","dogeusd","api3usd","mirusd","ctxusd","alcxusd","ankrusd","ftmusd","xtzusd","axsusd","usdcusd","slpusd","lunausd","ustusd","mco2usd","dogebtc","dogeeth","cvcusd","spellusd","mimusd","galausd","mcusd","ensusd","elonusd","ashusd","wcfgusd","rareusd","radusd","qntusd","maskusd","fetusd","audiousd","nmrusd","rlyusd","rndrusd","shibusd","ldousd","kp3rusd","tokeusd","efilfil","gusdusd"]
target_currencies = {"usd", "btc", "eth", "fil", "sgd", "gbp", "eur", "dai", "bch", "ltc"}
currency_combination_dictionary = defaultdict(set)
for currency_combo_string in currency_combo_strings:
for target_currency in target_currencies:
if currency_combo_string.endswith(target_currency):
currency_one = currency_combo_string.removesuffix(target_currency)
currency_combination_dictionary[currency_one].add(target_currency)
sorted_target_currencies = sorted(list(currency_combination_dictionary.keys()))
for target_currency in sorted_target_currencies:
value_list = ", ".join(sorted(currency_combination_dictionary[target_currency]))
print(f"{target_currency}: {value_list}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment