What would be the most efficient way to do the following:
genres = [value_from_key(wb, 'Genre (1)', n),
value_from_key(wb, 'Genre (2)', n),
value_from_key(wb, 'Genre (3)', n),
value_from_key(wb, 'Genre (4)', n),]
I tried doing it with a list comprehension — genres = [value_from_key(wb, 'Genre (%s)'%(i), n) for i in range[1,4]], but it kept raising a TypeError saying object is unsubscriptable. What would be the DRY way of doing the above? Thank you.
Replace the square brackets
[1,4]with round braces(1,4)in your call torange: