0

I am very new with Python and I am trying to print a single object from a unicode array that I retrieved from my server. My array look like this when I print the results:

{u'results': [{u'playerName': u'Sean Plott', u'score': u'12'}]

I would like to print the result in playerName as a string only. Thanks in advance.

2
  • Why convert it? You are also missing a closing brace. Should be: {u'results': [{u'playerName': u'Sean Plott', u'score': u'12'}]} Commented Oct 10, 2016 at 23:52
  • Are you just looking to print it pretty? Commented Oct 10, 2016 at 23:55

1 Answer 1

3

You should spend some time looking up dictionaries and lists in python. You currently have a dictionary with a list in it, and a dictionary inside of that list.

Here's the official reference guide on Python data structures:

https://docs.python.org/3/tutorial/datastructures.html

That being said, here's an example:

>>> d = {u'results': [{u'playerName': u'Sean Plott', u'score': u'12'}]}
>>> d["results"]
[{'score': '12', 'playerName': 'Sean Plott'}]
>>> d["results"][0]["playerName"]
'Sean Plott'
Sign up to request clarification or add additional context in comments.

3 Comments

He has a list with a dict inside it you mean
He has a dict with a list with a dict in it
Thanks, this got me to where I wanted to! Thumbs up

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.