-1

I have

['2','8','5']

And I want

[2,8,5]

and this class still list. Please help me

  • 2
    Are you saying you want to work with a list of numerical values or that you want the list to print without the quote marks? – Woody1193 Feb 07 '22 at 02:59

3 Answers3

0

Your issue is that your object is a list of strings, not a list of integers. You can fix this by doing the following:

[int(x) for x in l]

where l is your list.

Woody1193
  • 4,413
  • 1
  • 28
  • 58
0

You could use a list comprehension to create a new list where you've converted the strings to integers.

>>> test = ['2','8','5']
>>> test = [int(value) for value in test]
>>> test
[2, 8, 5]
tdelaney
  • 63,514
  • 5
  • 71
  • 101
0

use the join function
', '.join(list) # list is your list

The element in ' ' is the separation, whatever you want to separate the lost items from I'm this case a ',' This will print 2, 8, 5 To add closed brackets you can print

print(f"[{', '.join(list)}]")

Just add closed brackets after and before the new variable of join function (or if you don't want new variable you can simply put the join function there like I did); to the print function. I used a formatted string as I find it comfortable. Making string into integers will work but only for integers and not if there was something else in the list

ROOP AMBER
  • 301
  • 8