Python Forum
Convert element of list to integer(Two dimentional array)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Convert element of list to integer(Two dimentional array)
#3
Or you could use the following which will allow mixed numbers and strings:
>>> mylist = ['1', '4', '6', '8', 'hello', '7']
>>> newlist = [int(item) if item.isdigit() else item for item in mylist]
>>> newlist
[1, 4, 6, 8, 'hello', 7]
>>>
Reply


Messages In This Thread
RE: Convert element of list to integer(Two dimentional array) - by Larz60+ - Jun-11-2018, 11:57 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Turn list of arrays into an array of lists Cola_Reb 6 3,095 Jul-20-2022, 06:55 PM
Last Post: Cola_Reb
  numpy 2-dimentional rwahdan 3 3,079 Sep-21-2021, 07:40 PM
Last Post: deanhystad
  RandomForest --ValueError: setting an array element with a sequence JaneTan 0 2,538 Sep-08-2021, 02:12 AM
Last Post: JaneTan
  convert a list of string+bytes into a list of strings (python 3) pacscaloupsu 4 13,493 Mar-17-2020, 07:21 AM
Last Post: markfilan
  I am trying to change the value of an element in a record array ingu 1 2,963 Jan-14-2020, 01:30 PM
Last Post: perfringo
  TensorFlow get error - array with more than one element is ambiguous vokoyo 3 6,955 Nov-07-2019, 01:12 PM
Last Post: ThomasL
  How convert multidimensional array to two dimensional array tkkhan44 1 4,216 Feb-20-2019, 05:00 AM
Last Post: scidam
  How to add an element such as an average to a multi-dimensional array? xhughesey 6 5,663 Jan-06-2019, 10:47 PM
Last Post: xhughesey
  ValueError: The truth value of an array with more than one element is ambiguous. Eliza5 1 15,626 Apr-02-2018, 12:03 AM
Last Post: scidam
  Importing matlab cell array (.mat) into a python list scanato 0 9,650 Nov-15-2017, 11:04 AM
Last Post: scanato

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020