Let's assume that one has one list: lst = [name, surname, phone, email]
and one dictionary data={"name": "Mary", surname: "Smith", "phone": "123", "email": "mail@domain.com"}
.
I want to preapre code like this:
sample_object.add('user').prop('name': data['name']).prop('surname': data['surname']).prop('phone': data['phone']).prop('email': data['email']).do()
The problem is that I want to make id dynamically, the static parts are: sample_object.add('user')
and .do()
. The middle part is dynamic that means that my list can contain e.g. 7 elements and the values could be various.
Theoretically, I can concatenate strings in for loop and then use exec
on the string but I found it as an ugly solution. How can I do it in a pythonic way?