Is there anything that performs the following, in python? Or will I have to implement it myself?
array = [0, 1, 2]
myString = SOME_FUNCTION_THAT_TAKES_AN_ARRAY_AS_INPUT(array)
print myString
which prints
(0, 1, 2)
Thanks
You're in luck, Python has a function for this purpose exactly. It's called join
.
print "(" + ", ".join(array) + ")"
If you're familiar with PHP, join
is similar to implode
. The ", "
above is the element separator, and can be replaced with any string. For example,
print "123".join(['a','b','c'])
will print
a123b123c
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