lst = ['did', 'is', 'not', 'come', 'will', 'kill', 'are', 'not'] def new_element(item): return item[0] if item[1] != 'not' else ' '.join(item) new_list = [new_element(x) for x in zip(lst[:-1],lst[1:]) if x[0] !='not'] # ALTERNATIVE, NOT VERY PYTHONIC ONE-LINER new_list2 = [item[0] if item[1] != 'not' else ' '.join(item) for item in zip(lst[:-1],lst[1:]) if item[0] !='not'] print new_list print new_list2
How can I unite some elems in the list?
Messages In This Thread |
How can I unite some elems in the list? - by Mike Ru - Jul-23-2017, 10:25 PM
RE: How can I unite some elems in the list? - by Larz60+ - Jul-23-2017, 10:45 PM
RE: How can I unite some elems in the list? - by Mike Ru - Jul-24-2017, 05:04 PM
RE: How can I unite some elems in the list? - by wavic - Jul-25-2017, 07:21 AM
RE: How can I unite some elems in the list? - by Mike Ru - Jul-25-2017, 08:46 AM
RE: How can I unite some elems in the list? - by buran - Jul-25-2017, 10:50 AM
RE: How can I unite some elems in the list? - by nilamo - Jul-26-2017, 04:28 PM
RE: How can I unite some elems in the list? - by snippsat - Jul-26-2017, 05:38 PM
|
Users browsing this thread: 1 Guest(s)