How to check if the starting digit are similar in a list of numbers in Python

2 Answers

0 votes
lst = [3, 336, 3908899, 3126, 377] 
  
result = len(set(sub[0] for sub in  map(str, lst))) == 1
   
print(result) 
      
 
        
'''
run:
 
True
        
'''

 



answered May 2, 2020 by avibootz
0 votes
lst = [3, 336, 3908899, 3126, 4377] 
  
result = all(str(i)[0] == str(lst[0])[0] for i in lst) 
   
print(result) 
      
 
        
'''
run:
 
False
        
'''

 



answered May 2, 2020 by avibootz
...