Apr-28-2018, 01:02 AM
i'm build a set of options for a command in a list. i have a list of directories to exclude. i have wanted to do this kind of thing many times before. i want to make a list comprehension that has TWO (2) elements for each iteration of the given iterator.
i can do this in a construction loop like:
what = ['ab','bc/de','fg/hi/jk'] ... newlist = [... '--exclude' ... for x in what]that code should make newlist refer to (for example)
['--exclude','ab','--exclude','bc/de','--exclude','fg/hi/jk']
i can do this in a construction loop like:
what = ['ab','bc/de','fg/hi/jk'] ... newlist = [] for x in what: newlist.append('--exclude') newlist.append(x)and i end up doing that, or something like it. but i'd like to get this into a one line comprehension that is clear code.