-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpful.py
49 lines (28 loc) · 783 Bytes
/
helpful.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""
A collection of small, helpful functions I'll be using a lot.
Author:
Chris Nitsas
(nitsas)
Language:
Python 3(.4)
Date:
April, 2012
"""
__name__ = 'helpful'
__all__ = ['read_int', 'read_float', 'read_list_of_str',
'read_list_of_int', 'read_list_of_float']
# In every function below, 'file' is an open file object.
def read_int(file):
return int(file.readline())
def read_float(file):
return float(file.readline())
def read_list_of_str(file):
return file.readline().split()
def read_list_of_int(file):
return list(map(int, read_list_of_str(file)))
def read_list_of_float(file):
return list(map(float, read_list_of_str(file)))
def is_odd(num):
return num & 1 == 1
def is_even(num):
return not (num & 1 == 1)