Comparison of programming languages (associative array): Difference between revisions

Content deleted Content added
Citation bot (talk | contribs)
Removed parameters. | You can use this bot yourself. Report bugs here. | Suggested by Abductive | via #UCB_webform 3/15
m Cobra: {{sxhl}}
Tag: nowiki added
Line 191:
===Cobra===
Initializing an empty dictionary and adding items in [[Cobra (programming language)|Cobra]]:
{{sxhl|2=python|1=<nowiki/>
 
dic as Dictionary<of String, String> = Dictionary<of String, String>()
dic.add('Sally Smart', '555-9999')
Line 198:
assert dic['Sally Smart'] == '555-9999'
}}
 
Alternatively, a dictionary can be initialized with all items during construction:
{{sxhl|2=python|1=<nowiki/>
 
dic = {
'Sally Smart':'555-9999',
Line 206:
'J. Random Hacker':'553-1337'
}
}}
 
The dictionary can be enumerated by a for-loop, but there is no guaranteed order:
{{sxhl|2=python|1=<nowiki/>
 
for key, val in dic
print "[key]'s phone number is [val]"
}}
 
===D===