Reputation: 502
Quick question. I can't find the syntax for it (well assuming it exists) for creating an object from a for loop. What is the correct way to do this -
letters = ['a', 'b', 'c']
objs = (letter[index]:index for letter, index in letters)
#Also tryed..
objs = ({letter[index]:index} for letter, index in letters)
Any ideas?
Upvotes: 0
Views: 460
Reputation: 146064
coffee> letters = ['a', 'b', 'c']
[ 'a', 'b', 'c' ]
coffee> lettersToIndex = {}
{}
coffee> lettersToIndex[letter] = index for letter, index in letters
[ 0, 1, 2 ]
coffee> lettersToIndex
{ a: 0, b: 1, c: 2 }
Upvotes: 2