python 2.7 - Extend every single string in a list with punctuation -
I have a long list like:
['this', 'hello' 'Good', ...] Now I want a new list that looks:
['this',' this. ',' Hello, 'hello', 'hello', 'hello', 'hello!', 'Hello:', 'good', 'this', 'this', 'it:', 'hello', 'hello' Good ', ...] So I want to add a punctuation mark to each word. Is this also possible?
This would be an easy way:
Nihilist = [] old list For items in: newlist.append (item) newlist.append (item + '.') Newlist.append (item + ',') newlist.append (item + '?') Newlist.append (item + '!' 'Newlist.append (item +': ') slightly shorter:
adds nilist = [] = [' ',', ', To be added to the list: newlist.append (item + plus) or as an understanding of the list: '.', '!', ':' < Pre> adds = ['', ',', '.', '?', '!', ':'] Nilist = [item + Adds] As a single liner:
nilist = [add item [*], [, ',', '' Add items to the old list to add. ','? ','! ',': ']]
Comments
Post a Comment