0

In my Flask application, I receive the following data structure:

{"privMap":{"privKeys":["it","de"],"privValues":["Ciao","Hallo"]}}

which is sent by a JavaScript code (where I can access single pairs for example with translations.get('it');). How can I loop through this data structure in Python?

1
  • Sure. Thank you for asking. It was a structure I have never handled before in Python. But having seen the answer of Pouya, I should have come to the solution myself. Commented Jul 16, 2021 at 20:00

1 Answer 1

2

Use zip() to pair two lists and get tuples.

data  ={"privMap":{"privKeys":["it","de"],"privValues":["Ciao","Hallo"]}}

privKeys = data['privMap']['privKeys']
privValues = data['privMap']['privValues']

for item in zip(privKeys, privValues):
    print(item)

And this is the result:

('it', 'Ciao')
('de', 'Hallo')
Sign up to request clarification or add additional context in comments.

Comments

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.