0

I am in python and I have this:

places = [{'placeId':5},{'placeId':2}]

and this(note that the workout has a lot more data than 'To' and 'Exercise'.. I didnt wrote them all):

workout={'To': 'John' , 'Exercise': 'pull-ups'}

and I want to make this:

Emailwork={'To': 'John' , 'Exercise': 'pull-ups', 'places':[5,2]}

Can I have some help please?

1 Answer 1

2

Use a list comprehension listed in your dictionary in order to retrieve the values:

workout = {'To': 'John' , 'Exercise': 'pull-ups', 'places': [i['placeId'] for i in places]}
Sign up to request clarification or add additional context in comments.

4 Comments

Sorry my friend but I edited my question a bit.. and I would also prefer a more pythonic way to do it.. cause the data are too many and I cant just add at the end of the dictionary the 'places'.
I used in first place your (('places': [i['placeId'] for i in places])) to make places a list.... Now I need a pythonic way to add the 'places':[5,2] in the end of the workout thing..
This works as is. You're problem is that a dictionary is not ordered, meaning that places, exercise, and to can appear in any order when printed.
you are right.. I append the list in the workout with workout['places']=places .. and everything is working correctly now.. thank you!

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.