Issue
I have the next tuple as result of a sql query:
tuple1 = [(245, 57)]
tuple2 = [(11249, 5728)]
tuple3 = [(435, 99)]
and I need to divide the 57 between 245 and the same with the rest.
I can access individual elements with:
[x[0] for x in rows]
but when I do:
a = [x[1] for x in rows] / [x[0] for x in rows]
I get TypeError: unsupported operand type(s) for /: 'list' and 'list'
Solution
a = [x[1] for x in rows] / [x[0] for x in rows]
will attempt to divide a list by a list.
What you meant to do is:
a = [x[1] / x[0] for x in rows]
which is divide elements per item in list.
Answered By - Danny Varod
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.