0

creating a string from the items of secondary if main string met the condition

Hi, I work on a code and i have difficulties on a part of it. There is main string: '(a bc defg.)' The secondary string: 'iamhere' I want to create a new string by comparing these two strings and get: '(i am here.)' condition: if item in main string is not a letter, then add item to new string. Else add item of secondary string into the new string i could not do it for loop using isalpha function. Anybody have an idea how can i achieve the desired string?

14th Oct 2021, 10:37 AM
Hercule Poirot
Hercule Poirot - avatar
6 Answers
+ 3
mst="abcde." sst="hello" newst=sst + "".join(i for i in mst if not i.isalpha()) print(newst)
14th Oct 2021, 12:08 PM
ubai
ubai - avatar
+ 2
(i am here.) make sense o='(a bc defg.)' s='iamhere' s =list(s) for i in range(len(o)): if not o[i].isalpha(): s.insert(i,o[i]) print(''.join(l for l in s))
14th Oct 2021, 3:33 PM
ubai
ubai - avatar
+ 1
Hercule Poirot you can’t get (hello.) by comparing this strings there is no “l” and “o” letters
14th Oct 2021, 12:37 PM
ubai
ubai - avatar
0
@ simba if item in main string is not a letter, then add item to new string. Else add item of secondary string into the new string
14th Oct 2021, 11:57 AM
Hercule Poirot
Hercule Poirot - avatar
0
ubai not exactly. actually there are parenthesis too. i edited my sample strings to make my question clearer.
14th Oct 2021, 12:26 PM
Hercule Poirot
Hercule Poirot - avatar
0
ubai ty a lot it worked 😀
14th Oct 2021, 3:55 PM
Hercule Poirot
Hercule Poirot - avatar