I have a nested python for loop and need to append 2 times a value, is the code below PEP8 valid? Or there is a better pythonic way to to write the function?
def function():
empty_list = []
my_list = ['a', 'b', 'c']
for letter_1 in my_list:
for letter_2 in my_list:
empty_list.append(letter_1)
empty_list.append(letter_2)
return empty_list
itertoolsreturn list(chain.from_iterable(product(my_list, repeat=2))itertoolsas @Barmar suggests as well, but even without that, I would useextend()rather than callappend()twice..empty_list.extend((letter_1, letter_2))