Python Forum
Splitting A String In Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Splitting A String In Python
#5
>>>I have to do it in just one line

>>If i just use feedback.split()
it returns words as individual elements of a list
BUT,
what I want is that the length of each element of the list should be of the parameter (s).
How do I configure length of each split?

>>The other thing is,
if two words have a joint length less than (size) , they should be stored as a single element,which the .split() function does not do.

>>If i just use a list compression,
I will have to write a long piece of code that will check for white spaces and then recognize the character behind the whitespaces as single words, check their length, add the next word if it can satisfy the (size) criteria.

[feedback[i:i+size] for i in range(0, len(feedback), size)]

it will just read individual characters and not words and then store them by size in a list .
Reply


Messages In This Thread
Splitting A String In Python - by Saif133 - Jan-13-2017, 01:54 PM
RE: Splitting A String In Python - by Kebap - Jan-13-2017, 02:05 PM
RE: Splitting A String In Python - by Saif133 - Jan-13-2017, 02:43 PM
RE: Splitting A String In Python - by Mekire - Jan-13-2017, 03:07 PM
RE: Splitting A String In Python - by Saif133 - Jan-13-2017, 04:04 PM
RE: Splitting A String In Python - by Mekire - Jan-13-2017, 05:10 PM
RE: Splitting A String In Python - by Saif133 - Jan-14-2017, 04:09 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Using a function: splitting, joining, and slicing a string Drone4four 2 4,856 Dec-27-2018, 07:52 AM
Last Post: perfringo
  [split] Splitting a string into six pieces susmis666 1 2,219 Dec-25-2018, 06:16 PM
Last Post: ichabod801
  Quickest way of splitting a string yanhto 1 2,464 May-01-2018, 12:24 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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