4 ms·
Agreed - this is pretty much the perfect use case for list comprehensions, which are one of the best features of Python. Normally "oh but there's a better way t
by NoboruWataya 4y ago
Agreed - this is pretty much the perfect use case for list comprehensions, which are one of the best features of Python. Normally "oh but there's a better way to do it in that language" isn't a particularly interesting observation, but here it completely turns the author's point on its head. I can't think of many more elegant ways to convert a list of ints to floats, in any language, than `[float(i) for i in integerlist]`.
- chillpenguin 4y agoI agree. But regarding > I can't think of many more elegant ways to convert a list of ints to floats, in any language, than `[float(i) for i in integerlist]`. I think something like `integerlist.map(float)` is at least a contender.
- pcthrowaway 4y agoI prefer the python syntax generally, but throw in some typing with Typescript inferring the post-map type from the map function's return type, and I'd definitely go with `integerlist.map(float)`
- enriquto 4y ago> I can't think of many more elegant ways to convert a list of ints to floats, in any language, than `[float(i) for i in integerlist]`. What about `float(integerlist)`
- nawgz 4y agoI don't think writing a function called `float` that apparently accepts arrays as an argument is very elegant at all