Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3306154
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:15:17+00:00 2026-05-17T21:15:17+00:00

I’ve got a long string object which has been formatted like this myString =

  • 0

I’ve got a long string object which has been formatted like this

myString = “[name = john, family = candy, age = 72],[ name = jeff, family = Thomson, age = 24]”

of course the string is longer than this.
Also i have 3 lists with related names:

Names    = []
Families = []
Ages     = []

I want to read that string character by character and take the data and append it into appropriate lists. Can anyone help me on this about how to separate the string into variables?
The thing I need is something like this:

Names = [“john”, “jeff”, ...]
Families = [“candy”, “Thomson”, ...]
Ages = [72, 24, ...]
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T21:15:18+00:00Added an answer on May 17, 2026 at 9:15 pm

    This can be most easily done using a regex. Basically, construct a regex that extracts the name,family and age from the string and extract the relevant data from the tuples returned to build your lists.

    import re
    
    if __name__=='__main__':
        myString = "[name = john adams, family = candy, age = 72],[ name = jeff, family = Thomson, age = 24]"
        answers=re.findall("\\[\\s*name = ([^,]+), family = (\\w+), age = (\\d+)\\]",myString)
        names=[x[0] for x in answers]
        families=[x[1] for x in answers]
        ages=map(int,(x[2] for x in answers))
    
        print "names: ",names
        print "families: ", families
        print "ages: ", ages 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a long string which I want to split accross multiple lines so
I've got an ASP.Net application, which starts throwing NUllReferenceExceptions, after a long period of
I've got a Stateful Session bean where I create a object (in this case
While testing the below SQL code for another stackoverflow answer , I got the
I am prototyping Protobuf-net to replace some of our existing C# code which is
I got a OneToMany relation between User and Group Group.java @Entity public class Group
I've got two entities ServiceDownload.java @Entity public class ServiceDownload implements Serializable { private static
I've made a profiling method: @Around(tld.mycompany.business.aspects.SystemArchitecture.inServiceLayer() && !tld.mycompany.business.aspects.SystemArchitecture.publicConstructor()) public Object profileBusiness(ProceedingJoinPoint pjp) throws Throwable
public class XPBN extends Activity{ private Map _map; @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState);
I recently took all my code a manually imported it into an eclipse project

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.