I have a list, the list contains unicode elements I want to strip ')' and \n and blank space from the list. Essentially create a "clean" copy of the list.
My attempts reference this SO solution Remove specific characters from a string in python and python docs strings for 2.7.
I create my list using bs4 imports removed to minimise size.
def isNotBlank(myString):
if myString and myString.strip():
return True
return False
names = soup.find_all('span', class_="TextLarge")
bucket_list = []
for name in names:
for item in name.contents:
for value in item.split('('):
if isNotBlank(value):
bucket_list.append(value)
translation_table = dict.fromkeys(map(ord, ')(@\\n#$'), None)
[x.translate(translation_table) for x in bucket_list ]
so print(names) returns
[<span class="TextLarge">Mossfun (11) (Rtg:103)</span>, <span class="TextLarge">58.0</span>, <span class="TextLarge scratched">Atmospherical (8)
(Rtg:99)</span>, <span class="TextLarge">56.5</span>, <span class="TextLarge scratched">Chloe In Paris (7)
(Rtg:97)</span>, <span class="TextLarge">55.5</span>, <span class="TextLarge">Bound For Earth (5) (Rtg:92)</span>, <span class="TextLarge">55.5</span>, <span class="TextLarge">Fine Bubbles (4) (Rtg:91)</span>, <span class="TextLarge">55.5</span>, <span class="TextLarge">Brook Road (9) (Rtg:90)</span>, <span class="TextLarge">55.5</span>, <span class="TextLarge">Shamalia (10) (Rtg:89)</span>, <span class="TextLarge">55.5</span>, <span class="TextLarge scratched">Tawteen (6) (Rtg:88)</span>, <span class="TextLarge">55.5</span>, <span class="TextLarge">Ygritte (2) (Rtg:77)</span>, <span class="TextLarge">55.5</span>, <span class="TextLarge">Tahni Dancer (1) (Rtg:76)</span>, <span class="TextLarge">55.5</span>, <span class="TextLarge">All Salsa (3) (Rtg:72)</span>, <span class="TextLarge">55.5</span>]
and bucket_list returns as
[u'Mossfun ', u'11) ', u'Rtg:103)', u'58.0', u'Atmospherical ', u'8) \n ', u'Rtg:99)', u'56.5', u'Chloe In Paris ', u'7) \n ', u'Rtg:97)', u'55.5', u'Bound For Earth ', u'5) ', u'Rtg:92)', u'55.5', u'Fine Bubbles ', u'4) ', u'Rtg:91)', u'55.5', u'Brook Road ', u'9) ', u'Rtg:90)', u'55.5', u'Shamalia ', u'10) ', u'Rtg:89)', u'55.5', u'Tawteen ', u'6) ', u'Rtg:88)', u'55.5', u'Ygritte ', u'2) ', u'Rtg:77)', u'55.5', u'Tahni Dancer ', u'1) ', u'Rtg:76)', u'55.5', u'All Salsa ', u'3) ', u'Rtg:72)', u'55.5']
Hoping for
[['Mossfun', 11, 103, 58.0],[Atmospherical, 8, 99, 56.5]]
Currently it passes translation with all characters in place