Python Forum
List help to split into single entries
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
List help to split into single entries
#2
Never use list as a name. You overwrite built-in datatype list.

You should use 'extend' instead of 'append':

>>> lst =  ['A -> B', 'C -> D', 'E -> F']
>>> new_list = []
>>> for item in lst:
...     new_list.extend(item.split(' -> '))
... 
>>> new_list
['A', 'B', 'C', 'D', 'E', 'F']
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
List help to split into single entries - by paul41 - Nov-24-2019, 03:37 PM
RE: List help to split into single entries - by perfringo - Nov-24-2019, 03:43 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [split] why can't i create a list of numbers (ints) with random.randrange() astral_travel 7 1,610 Oct-23-2022, 11:13 PM
Last Post: Pedroski55
  How to split the input taken from user into a single character? mHosseinDS86 3 1,236 Aug-17-2022, 12:43 PM
Last Post: Pedroski55
  Split string using variable found in a list japo85 2 1,348 Jul-11-2022, 08:52 AM
Last Post: japo85
  How to get unique entries in a list and the count of occurrence james2009 5 3,049 May-08-2022, 04:34 AM
Last Post: ndc85430
  Split single column to multiple columns SriRajesh 1 1,366 Jan-07-2022, 06:43 PM
Last Post: jefsummers
  How to efficiently average same entries of lists in a list xquad 5 2,194 Dec-17-2021, 04:44 PM
Last Post: xquad
  Parse String between 2 Delimiters and add as single list items lastyle 5 3,469 Apr-11-2021, 11:03 PM
Last Post: lastyle
  convert List with dictionaries to a single dictionary iamaghost 3 2,907 Jan-22-2021, 03:56 PM
Last Post: iamaghost
  How to append multiple <class 'str'> into a single List ahmedwaqas92 2 2,385 Jan-07-2021, 08:17 AM
Last Post: ahmedwaqas92
  Undo interation to make a single list? DustinKlent 2 2,225 Nov-29-2020, 03:41 AM
Last Post: DustinKlent

Forum Jump:

User Panel Messages

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