This just has to be a dupe, but I just didn't find any existing instance of this question...
What is the easiest way to convert any iterable to an array in Python (ideally, without importing anything)?
Note: Ideally, if the input is an array then it shouldn't duplicate it (but this isn't required).
It depends on what you mean by array. If you really mean array and not list or the like, then you should be aware that arrays are containers of elements of the same (basic) type (see http://docs.python.org/library/array.html), i.e. not all iterables can be converted into an array. If you mean list, try the following:
l = list(iterable)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With