python - Lookup value inside dictionary-of-dictionary -


i'm creating python application input twitch emote name, , spits out link image. (i.e.; if input "kappa", result link this) can use api emote name , id, entries in returned json formatted such:

"id":{"code": "emote name","channel":"channel name", "set":"set number"} 

what want dictionary such:

{"emote name": "id", "emote name": "id"...} 

i've tried plenty of methods (parsing xml, key-value pairs), , nothing has worked. here's code far:

import requests  r = requests.get("http://twitchemotes.com/api_cache/v2/images.json") # here, i'd handle json response; don't know how. query_name = input("enter emote name:") k,v in emote_dict.items()   if k == query_name:     response = "http://static-cdn.jtvnw.net/emoticons/v1/" + v + "/1.0" print("here go: " + response) 

how using dict comprehension create dictionary want:

emote_dict ={value.get('code'):emote_id (emote_id, value) in r.json()['images'].iteritems()} query_name = raw_input("enter emote name:").strip() if query_name in emote_dict:     response = "http://static-cdn.jtvnw.net/emoticons/v1/" + emote_dict[query_name] + "/1.0" 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -