I have a simple dictionary:
{"keyy":{"key": "value", "cey": "value"}, "kaye":{"key": "value"}}
That I want to encode as a “context-aware” tuple:
[("keyy","key","value"), ("keyy","cey","value"), ("kaye","key","value")]
My attempt with ValueError: too many values to unpack:
if __name__=='__main__':
mydict={"keyy":{"key": "value", "cey": "value"}, "kaye":{"key", "value"}}
mytuplelist=[tuple(k,v,val) for (k,v) in [(key,val) for (key,val) in mydict]]
print mytuplelist
How would I go about creating this list of tuples?
using list comprehension :
output:
using Simple For-In loops:
output: