Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

dictionary to list python

# This is our example dictionary
petAges = {"Cat": 4, "Dog": 2, "Fish": 1, "Parrot": 5}
# This will be our list, epmty for now
petAgesList = []
# Search through the dictionary and find all the keys and values
for key, value in petAges.items(): 
  petAgesList.append([key, value]) # Add the key and value to the list
print(petAgesList) # Print the now-filled list
# Output: [['Cat', 4], ['Dog', 2], ['Fish', 1], ['Parrot', 5]]
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #dictionary #list #python
ADD COMMENT
Topic
Name
6+9 =