separation between string and integer | Sololearn: Learn to code for FREE!


separation between string and integer

Hi ✨ I need help in making a function that do like this : ... s="Af345gOh18" func(s) ... output: [345,18] ... suggest me haw i can do this ...thiss thing is very hard.. i was traying from day and 0 result 😅

5/22/2021 5:07:14 PM

Moha Riad

4 Answers

New Answer


Dude you should always include your code attempt, even if it doesn't make sense. We can help you write the code yourself by pointing out errors. Anyway, if you tried and got stuck, this should work: def numSep(str): arr = list(str) for elem in arr: if elem.isalpha(): arr[arr.index(elem)] = " " numArr = "".join(arr).split() for elem in numArr: numArr[numArr.index(elem)] = int(elem) print(numArr) numSep("Af345gOh18") Output: [345,18] Cheers✌


# with regex and list comprehension: import re print([int(s) for s in re.findall(r"\d+")])


Isaac Fernandes your solution still not working (I tested your previously attempt posted about 2 hours ago, that you've deleted just after)... it output: ["345","18"] you must then convert each string to numbers ^^


Check now.