Q:

Unable to get each element from variable "coin" to dictionary as key

How do I get dictionary from variable coin which I have define in my code. There are 32 elements in variable coin but I'm getting only one key and value which is TUSD in last line.

import requests
import json

r=requests.get('https://koinex.in/api/ticker') 
koinexData=r.json()
koinexprice = koinexData['stats']['inr']

for coin in koinexprice:
  print(coin)
  coindata={}
  coindata["koinex"]={
    coin:{
      "SellingPrice":koinexprice[coin]["highest_bid"],
      "buyingPrice":koinexprice[coin]["lowest_ask"]
      }
    }
#   data.append(coindata)
# print(data)``
# s = json.dumps(coindata)
print(s)

A:

You keep overwriting your coindata dictionary inside the loop, which is why only the last value remains. The second issue with your code is that you keep overriding the coindata['koinex'] dictionary inside the loop. This should be a list not a dictionary because you'll keep adding values to it.
If you move the initialization code outside the loop, you will not have this problem:
coindata = {}
coindata['koinex'] = [] # this should be a list, not a dictionary

for coin in koinexprice:
  print(coin)
  # Create a temporary dictionary d to hold the data you want
  # to add to coindata
  d = {coin: {'SellingPrice': koinexprice[coin]['highest_bid'],
              'buyingPrice': koinexprice[coin]['lowest_ask']}
      }

  coindata["koinex"].append(d) # add the new dictionary to the list

print(coindata)

