Monday, 26 August 2013

python join key and values from a dictionary

python join key and values from a dictionary

I have a dictionary that looks similar to this one :
mydic = {'key1':['va1','va2'], 'key2':['vb1','vb2']}
I would like to print file path out these, e.g.
/path/to/dir/key1/dir2/va1
/path/to/dir/key1/dir2/va2
/path/to/dir/key2/dir2/vb1
/path/to/dir/key3/dir2/vb2
I have tried,
for k, v in mydic.iteritems():
print "/path/to/dir/k/dir2/v"
But this one prints out v as a list. How can I achieve the above ? Thanks...

No comments:

Post a Comment