






Hotspots: Admin Pages | Turn-in Site |
Current Links: Case Final Project Summer 2007
Sp02 Final Exam Review: Transposing a Dictionary
Given a dictionary d, this produces a dictionary dt such that dt is the transpose of d.
dt := Dictionary new. d keysDo: [:key | dt at: (d at: key) put: key].
Technically, you can put any amount of code on one line. ;) Mitch's solution looks fine.
dt _ Dictionary newFrom: (d collect: [:value | Association key: value value: (d keyAtValue: value)]).
I just had to come up with an alternative, using my friend Mr. class method. Its technically a single statement.
On that thought, why are you encouraging single line coding?
The simplest way is not always the wrong way. Single lines of code only become negative when they hide the meaning. Or when you're in 2130. Hank Wilde
they say that the fewer lines of code there are, the less errors/bugs there will be.. ellie
Link to this Page