Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,104 questions

40,777 answers

573 users

How to get the first N numbers from a string in Python

2 Answers

0 votes
import re
 
s = 'python 34 java98 c++ 88397 php 3.14 swift 6-89'
 
lst = re.findall('[0-9]+', s)
 
n = 3
for i in range(n):
    print(lst[i])

   
   
'''
run:
   
34
98
88397

'''

 





answered Oct 27, 2020 by avibootz
0 votes
import re
  
s = 'python 34 java98 c++ 88397 php 3.14 swift 6-89'
  
lst = re.findall('[0-9]+', s)
  
n = 3
print(lst[0: 3])
 
    
    
'''
run:
    
['34', '98', '88397']
 
'''

 





answered Oct 27, 2020 by avibootz

Related questions

1 answer 61 views
1 answer 63 views
3 answers 120 views
1 answer 83 views
1 answer 65 views
...