I have
{key1:value1, key2:value2, etc}
I want it to become:
[key1,value1,key2,value2] , if certain keys match certain criteria.
How can i do it as pythonically as possible?
Thanks!
This should do the trick:
[y for x in dict.items() for y in x]
For example:
dict = {'one': 1, 'two': 2}
print([y for x in dict.items() for y in x])
This will print:
['two', 2, 'one', 1]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With