0

Hi,

My requirement is to identify '-' in string1 and delete those corresponding locations in string2. The logic I am implementing is that 1. find the locations in string1 where '-' occurs 2. At these locations, insert spaces in string2 and then 3. have string2 without spaces.

I managed to find the locations where '-' appears in the string1.

string1 = 'actttcttc-dsfsdf-yy'
locs = [match.start() for match in re.finditer(re.escape('-'), string1)]

I get the locations but now do not know how to proceed with the rest of my logic. If anyone has an idea how to proceed or better logic in Python, please advice.

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by pyTony
0

You could do:

string1 = 'actttcttc-dsfsdf-yy'
string2 = 'sacttctcpdsfsdfgysy'
print ''.join(s2 for s,s2 in zip(string1,string2) if s != '-')

Edited by pyTony: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.