dictionary - Python - getting values from nested dicitonary -


how build for loop in order print float values in nested dictionary, user?

   plist = {'user1': {u'fake plastic trees': 1.0, u'the numbers': 1.0, u'videotape': 1.0}} 

desired output = [1.0, 1.0, 1.0]

there's dict.values() method want.

a_dict = {'user1': {u'fake plastic trees': 1.0, u'the numbers': 1.0, u'videotape': 1.0}} first_key = list(a_dict.keys())[0] values = a_dict[first_key].values() print(list(values)) 

output

[1.0, 1.0, 1.0] 

edit: , if want return 1 flattened list of values keys mentioned in comments on question, can this:

a_dict = {     'user1': {u'fake plastic trees': 1.0, u'the numbers': 2.0, u'videotape': 3.0},     'user2': {u'foo': 4.0, u'bar': 5.0}, } values = [] k in a_dict.keys():     v in a_dict[k].values():         values.append(v) print(values) 

output

[4.0, 5.0, 3.0, 1.0, 2.0] 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -