import itertools
listTags = [ "TOT" , "WBA", "BUR", "SOU", "HUL", "SUN", "STK", "SWA", "ARS", "CHE", "MUN", "WHU", "WAT", "MID", "WHU", "CRY", "LEI", "EVE", "MCI", "LIV"]
combinations = ['#' + x + y for x, y in itertools.combinations(listTags, 2)]
print(combinations)
Output
['#TOTWBA', '#TOTBUR', '#TOTSOU', '#TOTHUL', '#TOTSUN', '#TOTSTK', '#TOTSWA', '#TOTARS', '#TOTCHE', '#TOTMUN', '#TOTWHU', '#TOTWAT', '#TOTMID', '#TOTWHU', '#TOTCRY', '#TOTLEI', '#TOTEVE', '#TOTMCI', '#TOTLIV', '#WBABUR', '#WBASOU', '#WBAHUL', '#WBASUN', '#WBASTK', '#WBASWA', '#WBAARS', '#WBACHE', '#WBAMUN', '#WBAWHU', '#WBAWAT', '#WBAMID', '#WBAWHU', '#WBACRY', '#WBALEI', '#WBAEVE', '#WBAMCI', '#WBALIV', '#BURSOU', '#BURHUL', '#BURSUN', '#BURSTK', '#BURSWA', '#BURARS', '#BURCHE', '#BURMUN', '#BURWHU', '#BURWAT', '#BURMID', '#BURWHU', '#BURCRY', '#BURLEI', '#BUREVE', '#BURMCI', '#BURLIV', '#SOUHUL', '#SOUSUN', '#SOUSTK', '#SOUSWA', '#SOUARS', '#SOUCHE', '#SOUMUN', '#SOUWHU', '#SOUWAT', '#SOUMID', '#SOUWHU', '#SOUCRY', '#SOULEI', '#SOUEVE', '#SOUMCI', '#SOULIV', '#HULSUN', '#HULSTK', '#HULSWA', '#HULARS', '#HULCHE', '#HULMUN', '#HULWHU', '#HULWAT', '#HULMID', '#HULWHU', '#HULCRY', '#HULLEI', '#HULEVE', '#HULMCI', '#HULLIV', '#SUNSTK', '#SUNSWA', '#SUNARS', '#SUNCHE', '#SUNMUN', '#SUNWHU', '#SUNWAT', '#SUNMID', '#SUNWHU', '#SUNCRY', '#SUNLEI', '#SUNEVE', '#SUNMCI', '#SUNLIV', '#STKSWA', '#STKARS', '#STKCHE', '#STKMUN', '#STKWHU', '#STKWAT', '#STKMID', '#STKWHU', '#STKCRY', '#STKLEI', '#STKEVE', '#STKMCI', '#STKLIV', '#SWAARS', '#SWACHE', '#SWAMUN', '#SWAWHU', '#SWAWAT', '#SWAMID', '#SWAWHU', '#SWACRY', '#SWALEI', '#SWAEVE', '#SWAMCI', '#SWALIV', '#ARSCHE', '#ARSMUN', '#ARSWHU', '#ARSWAT', '#ARSMID', '#ARSWHU', '#ARSCRY', '#ARSLEI', '#ARSEVE', '#ARSMCI', '#ARSLIV', '#CHEMUN', '#CHEWHU', '#CHEWAT', '#CHEMID', '#CHEWHU', '#CHECRY', '#CHELEI', '#CHEEVE', '#CHEMCI', '#CHELIV', '#MUNWHU', '#MUNWAT', '#MUNMID', '#MUNWHU', '#MUNCRY', '#MUNLEI', '#MUNEVE', '#MUNMCI', '#MUNLIV', '#WHUWAT', '#WHUMID', '#WHUWHU', '#WHUCRY', '#WHULEI', '#WHUEVE', '#WHUMCI', '#WHULIV', '#WATMID', '#WATWHU', '#WATCRY', '#WATLEI', '#WATEVE', '#WATMCI', '#WATLIV', '#MIDWHU', '#MIDCRY', '#MIDLEI', '#MIDEVE', '#MIDMCI', '#MIDLIV', '#WHUCRY', '#WHULEI', '#WHUEVE', '#WHUMCI', '#WHULIV', '#CRYLEI', '#CRYEVE', '#CRYMCI', '#CRYLIV', '#LEIEVE', '#LEIMCI', '#LEILIV', '#EVEMCI', '#EVELIV', '#MCILIV']
This answer relies on the use of itertools.combinations
:
itertools.combinations(iterable, r)
Return r length subsequences of elements from the input iterable.
Combinations are emitted in lexicographic sort order. So, if the input iterable is sorted, the combination tuples will be produced in sorted order.
Elements are treated as unique based on their position, not on their value. So if the input elements are unique, there will be no repeat values in each combination.