I am trying to pass multiple lines of lists from one function to another but I cannot figure out how it is done. Here is the code I have so far:
def readfile():
'''Read a text file; return a string holding the text'''
f = open("numbers.txt", 'r')
line = f.readlines()
f.close()
return line
def dataConversion(lines):
lst = []
for element in lines:
lst = element.strip()
lst = map(int, lst)
print lst
return lst
def evenNumberList(lsts):
print lsts
def main():
lines = readfile()
lsts = dataConversion(lines)
doubledList = evenNumberList(lsts)
main()
The output of the dataConversion(lines) function is:
[4, 3, 8, 8, 5, 7, 6, 0, 1, 8, 4, 0, 2, 6, 2, 6]
[4, 3, 8, 8, 5, 7, 6, 0, 1, 8, 4, 1, 0, 7, 0, 7]
[4, 0, 1, 2, 8, 8, 8, 8, 8, 8, 8, 8, 1, 8, 8, 1]
[4, 5, 5, 2, 7, 2, 0, 4, 1, 2, 3, 4, 5, 6, 7, 7]
[4, 5, 3, 9, 9, 9, 2, 0, 4, 3, 4, 9, 1, 5, 6, 2]
[4, 9, 9, 2, 7, 3, 9, 8, 7, 1, 6, 0, 0]
[4, 9, 9, 2, 7, 3, 9, 8, 7, 0, 0, 1, 7]
[8, 0, 8, 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
[5, 5, 8, 8, 3, 2, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
[5, 4, 9, 1, 9, 4, 6, 9, 1, 5, 4, 4, 4, 9, 2, 3]
[5, 4, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 8]
[3, 7, 8, 2, 8, 2, 2, 4, 6, 3, 1, 0, 0, 0, 5]
[3, 7, 1, 4, 4, 9, 6, 3, 5, 3, 9, 8, 4, 3, 1]
[3, 7, 1, 4, 4, 9, 6, 3, 5, 3, 9, 8, 4, 3, 1]
[3, 7, 8, 7, 3, 4, 4, 9, 3, 6, 7, 1, 0, 0, 0]
[3, 7, 8, 7, 3, 4, 4, 9, 3, 6, 7, 1, 0, 0, 1]
[6, 0, 4, 1, 2, 7, 3, 9, 9, 0, 1, 3, 9, 4, 2, 4]
[6, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 7]
[6, 0, 1, 1, 0, 0, 0, 9, 9, 0, 1, 3, 9, 4, 2, 4]
While the input to the evenNumberList(lsts) function is:
[6, 0, 1, 1, 0, 0, 0, 9, 9, 0, 1, 3, 9, 4, 2, 4]
How do I make them match? I need all of the lines of code in the evenNumberList(lsts) function not just the one line. My professor told me I need to call the function from within a loop but I haven't been able to figure out how to do that.