How to convert dictionary list values uniformly in Python 3?
<p>I have a yaml file with a couple of fields that are lists.</p>

<p>It looks kind of like this:</p>

<pre><code>key0: "value0"
key1: ["value1-0", "value1-1", "value1-2"]
key2: ["value2-0", "value2-1", "value2-2"]
key3: "value3"
</code></pre>

<p>This is naturally converted to a Python dictionary with the PyYAML library.</p>

<p>Eventually I want to get a string of keys and values smashed together as follows:</p>

<p><code>--key0 value0 --key1 value1-0 --key1 value1-1 --key1 value1-2 ... --key3 value3</code></p>

<p>I came up with a solution that is dependent on the fact that I'm dealing with lists but something bugs me and makes me want to ask if there is a more clean, generic and elegant way?</p>

<p>UPD: after @senchuk answer I wanted to make myself a little more clear.</p>

<p>The question is not about ANY solution. This is merely an opinion-based question for people who are more experienced with Python than I am. I'm constantly hearing about this "pythonic" way. This is what I'm looking for! Something with a hipster functional thingy would do. There's no limitation on data transformation whatsoever. If the best way is to convert all of the scalar values to lists and then convert everything to a string, so be it. I'm really curious how this is done today in modern Python.</p>

<p>If you already have something that converts what you've got into a dictionary, then this should do what you want</p>

<pre><code>d = {'key1' : 'value1', 'key2' : 'value2'}
stringFinal = ''
tempString = ''
for k, v in d.items():
    tempString = str(k) + ' ' + str(v)
    stringFinal ='--' + tempString + ' ' +  stringFinal
    tempString = ''
print(stringFinal)
</code></pre>

python python-3.x refactoring