I'd like to get a nice output of all keys (and possibly subkeys) within a dictionary. Hence I wrote:
print("The keys in this dictionary are:\n")
for k in mydict.keys():
print(k)
This works, however is there a more concise way to do this? I tried list comprehension, however this of course returns a list which I can't concatenate with may introduction string. Anything more functional that could be used?
EDIT: The dictionary might look like this:
mydict = {'key1':'value1',
'key2':{'subkey1':'subvalue1','subkey2':'subvalue2'}}
I'm open to the meaning of 'nice formatting'. However, maybe something like this:
key1
key2: subkey1, subkey2