Everywhere on the web I can find how to convert strings to integers but the opposite does not seem to be working. With this error (argument 2 to map() must support iteration)
My integers:
-0.707106781187
-1.0
-0.408248290464
0.0
The relevant parts of my code:
def calculateZscore(inFileName, outFileName):
inputFile = open(inFileName,"r")
txtfile = open(outFileName, 'w')
for line in inputFile:
newList = line.strip().split(',')
obsExp = newList[-2:]
obsExp = list(map(int, obsExp))
obs = obsExp[0]
exp = obsExp[1]
zScore = (obs - exp) / math.sqrt(exp)
zScore = list(map(str, zScore))
print zScore
if __name__ == "__main__":
main()
It looks like
zScore
will be a float. As your error message suggests, the second argument tomap()
must be an iterable (such as alist
,str
ortuple
).Unless I am missing something,
zScore
is always a single value, so you could probably get away with simply:I am not sure how you intend to use
zScore
later in your program, but from what you have in your example I don't see any advantage to usingmap
, unless you need to applystr
to a list or tuple of values.However, if you just want your current code to stop raising the error in question, then try replacing this:
with this:
Also,
map()
will return an iterator, so no need to calllist()
on the result unless you need to get all the values at once.