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.

You could do:

string1 = 'actttcttc-dsfsdf-yy'
string2 = 'sacttctcpdsfsdfgysy'
print ''.join(s2 for s,s2 in zip(string1,string2) if s != '-')
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.