I need a wast dictionary, it displays mostly typical values, as well as some unique ones. The 1st way to get this definition of one flat "explicit" dictionary literal is:
musicians = { 'ABBA': 'pop', 'Avril Lavigne': 'pop', ... 'Mikhail Krug': 'russian chanson', 'The Rolling Stones': 'rock', ... 'Zaz': 'jazz', }
2nd - "DRY" set of typical lists and a dictionary of special offers:
pop_musicians = [ 'ABBA', 'Avril Lavigne', ... ] rock_musicians = [...] unusual_musicians = { 'Mikhail Krug': 'russian chanson', 'Zaz': 'jazz', } musicians = dict( [(m, 'pop') for m in pop_musicians] + [(m, 'rock') for m in rock_musicians] + unusual_musicians.items() )
Suppose the key-value relationship is much more variable (the values โโof some keys may change) in my case than in this example.
How would you prefer and why? In your opinion, which one is more pythons?
source share