I simply want to convert an object that looks like this:
dict_values(['baf0242b-d7fc-49d7-aada-220344969fb6'])
That I got from doing this:
dictionary.values()
To a simple string: 'baf0242b-d7fc-49d7-aada-220344969fb6'
How can I?
3 Answers
Say you have a dictionary:
d = {'key': 'baf0242b-d7fc-49d7-aada-220344969fb6'}
The result you see is from running the following:
d.values()
To get what you want, convert it to a list and get the first item on it:
d = {'key': 'baf0242b-d7fc-49d7-aada-220344969fb6'}
result = list(d.values())[0]
list(your_dict.values())[0]
As @rdas mentioned, dict_values is a view in Python 3+, and the first index will return your string.
If you are getting the first value, or the only value in your case. This might be a bit more memory efficient:
next(iter(d.values())))