1
I’m starting in python and use a site that has several problems for resolution, in it the vectors and matrices are passed with the values separated by a space and not comma. For example:v = 1 2 3 43.
I know I can receive this value in the input and leave it as a string, the question is how to transform this string into an array. I wonder if there is any function I can convert, because if I "treat" that input I lose efficiency.
only do test=v.split() does not resolve ? will convert a space-separated string into a list...
– ederwander
try to use
map
or alist comprehension
.– Lucas Virgili
It will depend on one thing. Always, will each value be unique? Or can there be keys, like, with a compound name? for example: v = carlos silva 32 years other value
– Marcelo Aymone
What is your true entrance?
v = 1 2 3 43
or only1 2 3 43
? If this is the second case, the @ederwander comment solves (by the way, post this as a response). Otherwise, you can first separate the key from the value usingx = entrada.split('=')
and then separate each individual value usingx[1].split()
.– mgibsonbr
mgibsonbr get 1 2 3 45 65, @ederwander’s comment was very helpful, and I can get to a list, only the list is composed of strings. ['1','2','3','43'], is there a way to turn this list of strings into a list with numbers using some function? I can only imagine trying to convert one by one.
– Lucas Ildefonso