Something like this using a generator function:
lis = ['ALRAGUL','AKALH', "AL", 'H','ALH' ,'to7a','ALRAGULH']
def solve(lis):
for x in lis:
if x.startswith("AL") and x.endswith("H"):
yield x[:2]
if len(x)>4:
yield x[2:-1]
yield x[-1]
elif x.startswith("AL"):
yield x[:2]
if len(x)>2:
yield x[2:]
elif x.endswith("H"):
if len(x)>1:
yield x[:-1]
yield x[-1]
else:
yield x
new_lis = list(solve(lis))
print new_lis
output:
['AL', 'RAGUL', 'AKAL', 'H', 'AL', 'H', 'AL', 'H', 'to7a', 'AL', 'RAGUL', 'H']
4
solved Modify list in Python