EDIT: Clarified the question a bit
How can I get a string from a dictionary with the format
key1 = value1
key2 = value2
in a relatively fast way ? (relative to plain concatenation)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There’s no reason to use list comprehension here.
Python 3.x:
Python 2.x:
EDIT because of comment by OP in another answer:
If you’re passing it to a function and not printing it here, then you should just pass the generator to the function, or the dict itself and let the function handle whatever it needs to do with it.
This is much better than converting it to a string inside a scope where it’s not even needed. The function should do that, since that’s where it’s used.
I made a wrapper function, since editing the main function is out of the question.