Created
February 20, 2017 02:44
-
-
Save 2hands10fingers/f1723da3f00c8983b9d51a490619b9dd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
class MyProcessingClass: | |
def __init__(self, str_list): | |
self._str_list = str_list | |
self._float_list = [] | |
self._strings_to_floats() | |
# the function to convert the list | |
# of strings into a list of floats | |
def _strings_to_floats(self): | |
for i in self._str_list: | |
try: | |
num = int(i) | |
if not math.isnan(num): | |
self._float_list.append(num) | |
except ValueError: | |
pass | |
# process the list of floats in some way | |
def process_input(self): | |
print(self._float_list) | |
input_1 = list("123abc") | |
proc_1 = MyProcessingClass(input_1) | |
proc_1.process_input() | |
input_2 = ['1.2', '2', 'NaN', 'foo', '0x8', 'bar'] | |
proc_2 = MyProcessingClass(input_2) | |
proc_2.process_input() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment