Python Forum
Change type of elements in a list by column
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Change type of elements in a list by column
#8
(Dec-28-2016, 07:54 PM)micseydel Wrote: Apologies, I tried to reply to this last night but my internet was having issues.

Here's something close to what you want
newList = [(name, int(num), f(time)) for (name, num, time) in myList]
where f() is whatever conversion you want for time.

I believe this is preferable over mutating things in-place, as a general habit, but if memory is a concern, you could write a loop over myList in which for each sublist, you use indexes to replace the values with their relative modifications.

Thank you!
it works
Reply


Messages In This Thread
RE: Change type of elements in a list by column - by tkj80 - Jan-04-2017, 11:15 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  unable to remove all elements from list based on a condition sg_python 3 468 Jan-27-2024, 04:03 PM
Last Post: deanhystad
Question mypy unable to analyse types of tuple elements in a list comprehension tomciodev 1 496 Oct-17-2023, 09:46 AM
Last Post: tomciodev
  Change font in a list or tuple apffal 4 2,704 Jun-16-2023, 02:55 AM
Last Post: schriftartenio
  Checking if a string contains all or any elements of a list k1llcod3 1 1,119 Jan-29-2023, 04:34 AM
Last Post: deanhystad
  How to change the datatype of list elements? mHosseinDS86 9 2,013 Aug-24-2022, 05:26 PM
Last Post: deanhystad
  search a list or tuple for a specific type ot class Skaperen 8 1,954 Jul-22-2022, 10:29 PM
Last Post: Skaperen
  find some word in text list file and a bit change to them RolanRoll 3 1,552 Jun-27-2022, 01:36 AM
Last Post: RolanRoll
  ValueError: Length mismatch: Expected axis has 8 elements, new values have 1 elements ilknurg 1 5,173 May-17-2022, 11:38 AM
Last Post: Larz60+
Question Change elements of array based on position of input data Cola_Reb 6 2,146 May-13-2022, 12:57 PM
Last Post: Cola_Reb
  TypeError: unsupported opperand type(s) for %: 'int' and 'list' cool_person 7 2,195 May-07-2022, 08:40 AM
Last Post: ibreeden

Forum Jump:

User Panel Messages

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