Re: Getting the first item in a dict

2020-01-27 Thread S D
I ended up using `dict[next(iter(dict))]` I am getting the dict as one of two dicts nested in a list from a weather service API. I do this using a list comprehension to call the API with coordinates for each location in another list. A mouthful. `resp = [fetch_api_data(location, request_id) for

Re: Getting the first item in a dict

2020-01-27 Thread Bill Freeman
Note that these give the only value. This won't work if you have more than one value in the dict, since you won't know which you will get. Where d is the dict: list(d.values())[0] or for i in d.values(): # use i here print(i) or d[list(d)[0]] I'm sure that there

Re: Getting the first item in a dict

2020-01-27 Thread Nick Sarbicki
show you the first item unless it was an > ordered dict. > > Mike > > > > > > Original message > From: S D > Date: 27/1/20 22:56 (GMT+10:00) > To: django-users@googlegroups.com > Subject: Getting the first item in a dict > > I have a diction

RE: Getting the first item in a dict

2020-01-27 Thread Mike Dewhirst
Can you use ddict[ddict.keys()[0]] ???I don't know if that would show you the first item unless it was an ordered dict. Mike Original message From: S D Date: 27/1/20 22:56 (GMT+10:00) To: django-users@googlegroups.com Subject: Getting the first item in a dict I have

Getting the first item in a dict

2020-01-27 Thread S D
I have a dictionary which contains one item (“current_location”, which is a nested dict) and I would like to access that nested dict. However, I cannot use the key as the code will break if a different key is passed, e.g. “different_location”. How can I access the first item in a dictionary