When learning new languages you always want to know the typical things like arrays, sorting, etc. Today I was messing around with some Python and noticed I had to look up how to create an array of objects.

Solution

#initialize the array
arr=[] 
#initialize an array with a list of tuples
arr= [("Forename","Stef"),("Surname","Van Looveren")] 

#print the values 
for Key,Value in Arr:  
    print Key,"=",Value

 As of Python 3.7, regular dicts are guaranteed to be ordered, so you can just do

Dictionary = {"Forename":"Stef","Surname":"Van Looveren"}
for Key,Value in Dictionary.items():
  print(Key,"=",Value)

 

 

Saved you some valuable time?

Received 100 so far from 4 kind contributors.