fork download
  1. items = ['1', '2', '-10', 'A', '1234567890']
  2.  
  3. for item in items:
  4. print('{} type: {}'.format(item, type(item)))
  5.  
  6. int_items = [int(value) for value in items if value.lstrip('-').isdigit()]
  7. print()
  8.  
  9. for item in int_items:
  10. print('{} type: {}'.format(item, type(item)))
  11.  
Success #stdin #stdout 0.04s 9576KB
stdin
Standard input is empty
stdout
1 type: <class 'str'>
2 type: <class 'str'>
-10 type: <class 'str'>
A type: <class 'str'>
1234567890 type: <class 'str'>

1 type: <class 'int'>
2 type: <class 'int'>
-10 type: <class 'int'>
1234567890 type: <class 'int'>