Issue
myDict = {"word" : [10],
"other word" : [16]}
I was wondering how I would be able to print this out in this format:
word 10
other word 16
Solution
Iterate over the key/value pairs in the dict and print them line by line is a solid starting point for the majority of cases:
for key, value in myDict.items():
print(key, *value, sep = " ")
You need to use the *
or destructuring operator because your value is a list
.
For a more in-depth examination of several examples, the following is an excellent example from the documentation: https://docs.python.org/3/tutorial/datastructures.html#looping-techniques
Answered By - Simon Provost
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.