src.HotKeys.Insert(num,text)
src.HotKeys[text]=element
Problem description:
The above is my current solution but I would like to insert the association in one statement. Like...
src.HotKeys.Insert(num,text=element)
//or
src.HotKeys.Insert(num,list(text=element))
Also, how would one get an element of an associative list if he knew the position of the element but wanted to retrieve the element not its associative value without looping thru the list. For instances
var/list/HotKeys=list("A"="Punch","S"="Kick","D="Jump")
for(var/i=1,i<=HotKeys.len,i++)
var/elem="The element I want to retrieve"
world<<"You pushed [elem] to perform the action [HotKeys[i]]"
No such luck. Inserting an element at a specific position of a list and assigning an associated value are entirely different operations and there's no shortcut that I know of to assign them properly. If you are using an associative list, you should not be depending on order being consistent.
If you know the KEY of the element:
l[key] //gets value
If you know the position of the key:
l[pos] //gets key
If you know the position of the key and want the value:
l[l[pos]] //gets value
If you know the value you want to find, but want to find the key it is stored under:
//You probably shouldn't actually be using an associative list.
Associative lists are intended for quick lookups and storage of known unique key-value pairs. They do not need to be ordered in a particular sequence and you should not be depending on values being unique because that's not a pattern that they are good for.
Odds are that you are using the wrong approach if you need any of the behavior that they aren't good for, or you need to build a linked-list approach using multiple different kinds of list storage schemes to keep track of the desired function for different purposes related to the same associative list.
Lastly:
You should never need to know what elem is, because at some point the player had to push a key to trigger the action. If at some point later on down the call chain you need to know what key is pressed, it's because you discarded a value you already knew. Pass it down the chain as an argument rather than searching for it.
So, basically, what you have going on in the example is a situation where:
Vs what you ought to be doing: