Im using 2 objects inside my class. My actions are almost identical, however I want to return 2 different data types and both are slightly different from each other.
import requests class coins: def coins_arr(self): params = {'limit': 10, 'convert': 'USD'} data = requests.get('https://api.coinmarketcap.com/v1/ticker/?%s' % params).json() coinsData = [] for objects in data: for k in objects.keys(): if k == 'id': coinsData += objects[k].split() return sorted(coinsData) def coins_dict(self): params = {'limit': 10, 'convert': 'USD'} data = requests.get('https://api.coinmarketcap.com/v1/ticker/?%s' % params).json() coinsDict = {} for objects in data: for k,v in objects.items(): if k == 'id': coinsDict.update({objects[k]:objects['price_usd']}) return coinsDict d = coins() print (d.coins_arr())
I thought of returning the coins_dict.keys(), but it wont return me it in a sorted order. I am not sure if I can implement lambda function when I call the class object.
I would really appreciate feedback provided!