List with duplicated values and suffix
问题 I have a list, a : a = ['a','b','c'] and need to duplicate some values with the suffix _ind added this way (order is important): ['a', 'a_ind', 'b', 'b_ind', 'c', 'c_ind'] I tried: b = [[x, x + '_ind'] for x in a] c = [item for sublist in b for item in sublist] print (c) ['a', 'a_ind', 'b', 'b_ind', 'c', 'c_ind'] I think my solution is a bit over-complicated. Is there some better, more pythonic solution? 回答1: You could make it a generator: def mygen(lst): for item in lst: yield item yield