sodoesaburningbus sodoesaburningbus - 2 months ago 4
Python Question

Python -- list(some_float) fails but [some_float] works?

I have a case where a user passes a function a single floating-point value. While trying to put that value into a list for easier data handling later, I've discovered that I cannot make a list using

, but
does work. Python prints an error stating that "'float' object is not iterable."

My question for you wonderful people is why
works, but
does not. My understanding is that they produce identical results even if they are executed differently. I am using Python 3.4.3.


list(thing) doesn't mean "put thing in a list". It means "put thing's elements in a list". If you want to put a thing in a list, that's [thing].