>>> lis=['ALRAGUL','AKAL','to7a']
>>> for i in lis:if i.startswith('AL'): j=lis[lis.index(i)+1] L=list(itertools.repeat(j, 2)) lis[lis.index(i)+1]=Llis[lis.index(i)+1]=i[2: ] lis[lis.index(i)]='AL'
>>> print lis
['AL', 'RAGUL', 'to7a']
But I want the result to become :
['AL', 'RAGUL','AKAL' 'to7a']
and I want it somehow general meaning that the code works with whatever words are and with whatever arrangement of them is
For example I want it to split ('AL') under any conditions
thx alot :)
Answer
Something like this?
def separate(lst, chunk):for n in lst:if n.startswith(chunk):for x in n.partition(chunk)[1:]:yield xelse:yield n
And the output:
In [104]: list(separate(['ALRAGUL','AKAL','to7a'], 'AL'))
Out[104]: ['AL', 'RAGUL', 'AKAL', 'to7a']
This question already has answers here:How can I delete a file or folder in Python?(18 answers)Closed 5 years ago.I want do delete a file, for ex. myfile.txt that is stored under a hidden folder. Is i…
The following dictionary gives the word and its value:keywords = {alone: 1, amazed: 10, amazing: 10, bad: 1, best: 10, better: 7, excellent: 10, excited: 10, excite: 10}Following the dictionary are two…
Its difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying thi…
Its difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying thi…
This question already has answers here:Ask the user if they want to repeat the same task again(2 answers)Closed 5 years ago.Basically its a guessing game and I have literally all the code except for th…
This question already has answers here:How to test multiple variables for equality against a single value?(31 answers)Closed 10 years ago.This will probably be a dumb question, but why does this piece…
I have too many lines like this:>ENSG00000100206|ENST00000216024|DMC1|2371|38568257;38570043|38568289;38570286
CTCAGACGTCGGGCCGACGCAAGGCCACGCGCGCGAACACACAGGTGCGGCCCCGGGCCA
CACGCACACCGTACAC
>ENSG0…
I have a numpy array as follows:import numpy as np
a = np.array([1, 4, 2, 6, 4, 4, 6, 2, 7, 6, 2, 8, 9, 3, 6, 3, 4, 4, 5, 8])and a constant number b=6I am searching for a number c which is defined by t…
I was solving an arrays problem from GFG, where we need to find the index of the first repeating element. The question is as follows:
Given an array arr[] of size n, find the first repeating element. T…
Its difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying thi…