parsing text in python

my_string = 'Names: Romeo, Juliet'

# split the string at ':'
step_0 = my_string.split(':')

# get the first slice of the list
step_1 = step_0[1]

# split the string at ','
step_2 = step_1.split(',')

# strip leading and trailing edge spaces of each item of the list 
step_3 = [name.strip() for name in step_2]

# do all the above operations in one go
one_go = [name.strip() for name in my_string.split(':')[1].split(',')]

for idx, item in enumerate([step_0, step_1, step_2, step_3]):
    print("Step {}: {}".format(idx, item))

print("Final result in one go: {}".format(one_go))

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
parse text : with python parse text python python parse text string parse text in python python text parsing python parser text python parse text parser text python how to parse a string in python text parsing in python parsing "\n" in text python parse certain things with python parse a textfile structure python read dokument parser python parsing words in python how to parse a text in python parse files different syntax python text parsers python python best text file parser python3 best text file parser parse file conents python python based document parser python tutorial parsing text file parsel python text how to parse text parsing text from a file python parsing text from a file how to parse a program in python python program to parse a file and show resaults parse in text file python python parsing text file and matching on strings python parse text file how to parse text file in python easy parser to read output in python parse text file python parse text with python how to parsing in python parsing a data file in python how to parse a text string and turn it into python code how to parse txt file how to parse text file to parse the txt file in python how to parse a txt file in python best way to parse a file in python parse file in python parsing .txt data in python parsing text data in python how do you build a parser for text files notes or manual on parsing file in python parsing file in python text parsing python python parsing files python text parse python parse data from a text file parsing data out of txt python python parsing text files python text file parsing parsing text in python pars file python python parsing text python file parsing parsing a file in python parse a file in python
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source