-1

input : my_list = [1,2,3] output : 1,2,3

How to convert?

  • 1
    Are you asking how to print `1,2,3` from that list? Then `",".join(str(i) for i in ints)` Otherwise, your list is already a list of ints. no conversion is required. – joanis Jun 22 '21 at 12:07

3 Answers3

0

Please mention which language

const my_list = [1,2,3]
console.log(my_list.join()); -> this one will return 1,2,3 string


0

Code:

my_list = [1,2,3] 
ints = [int(item) for item in my_list]
print(ints)
Vijayaragavan K
  • 319
  • 1
  • 5
0

Looking at your expected output, did you intend to convert the list to a comma separated string? Is it in Javascript? Python? Haskell?

Already answered for javascript here and python here and Haskell here.


For Javascript using the join method.

const elements = [1, 2, 3];

console.log(elements.join());
// expected output: "1,2,3"

console.log(elements.join(''));
// expected output: "123"

console.log(elements.join('-'));
// expected output: "1-2-3"
vineetvdubey
  • 95
  • 1
  • 7