there is a need to extract more than the first order number from a string / list without using standard split join methods and all that. Up to ten, a comparison with numbers = '0123456789' is allowed, but what to do next? help me!) my version of the code is lower, but it does not distinguish 10 (

a = input() b = [] numbers = '0123456789' for i in a: if i in numbers: b.append(int(i)) else: continue print(b) вход: 3,5,7,9,10 выход: [3, 5, 7, 9, 1, 0] 
  • Have you tried to do something yourself? - hedgehogues
  • Try to reformulate the question so that it is clear what it is about. With examples of I / O, own attempts, etc. - Enikeyschik
  • ok, fixed ... - vladionair
  • What you did not please "split join and all that"? - andreymal
  • the task is this) or rather this is not the problem, but this is the main key ... I wonder!;) - vladionair

3 answers 3

 numbers = '0123456789' def qwerty(stri): (a, la, stri) = ('', 0, (' ' + stri)) for (e, s) in enumerate(stri): if s in numbers: la += 1 if not a: a = e elif la > 0: if la > 1: yield stri[a:e] (a, la) = ([], 0) continue if la > 1: yield stri[a:(e+1)] return print(*qwerty('11,3,5,7,9,10,11,2,12,1')) # 11 10 11 12 
  • ATP for the option! but it does not suit me unfortunately (but I will try to extract useful things from it;) - vladionair
  • removed join, the point is that you need to know the indices of a number in a line, and if there are several indices for a number (> 9), return the section cut by indices - vadim vaduxa
  • ok, ok, interesting! The meaning of the option is accepted! quite merci;) I pull out from here the fact that if several indices in a row goes a number, I return the cut! - vladionair
 input_data = '1A23D56R4ASDF12345S112' result = [] add = False base = 1 for ch in reversed(input_data): try: num = int(ch) * base if add: result[0] += num else: result.insert(0, num) add = True base *= 10 except ValueError: add = False base = 1 print(result) # [1, 23, 56, 4, 12345, 112] 
  • ATP for help, but unfortunately your option does not suit me ( - vladionair

everything was much easier. with negative it also works.

 a = input() b = [] s = str() numbers = '-0123456789' for i in a: if i in numbers: s += i continue else: if len(s) > 0: b.append(int(s)) s = str() if len(s) > 0: b.append(int(s)) print(b) вход: 0.[0000[/-1//1000,,[12345ю6789,, выход: [0, 0, -1, 1000, 12345, 6789]