Advertisement
vivaladiva

Untitled

Dec 16th, 2020
644
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.38 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. def evenItems(file):
  5.     evens = []
  6.     lines = file.read().splitlines()
  7.  
  8.     for line in lines:
  9.         evens.extend(filter(lambda x: int(x) % 2 == 0, line.split(',')))
  10.  
  11.     return evens
  12.  
  13. # Tests
  14. #
  15. # nums.txt data:
  16. # 11,43,2,5,9,111,4,2,8
  17. # 523,0,0,1,18,96,4
  18. # -9,110,15,668,664,3,8
  19.  
  20. print(evenItems(open('nums.txt', 'r')))
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement