Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

string conversion

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, ...]

Answer*

Draft saved
Draft discarded
Cancel
1
  • +1 for using named groups instead of relying on the format of the data to not change. In a one off script, maybe it doesn't seem worth the trouble, but it seems that I spend a lot of time maintaining what were supposed to have been one-off scripts. Commented Oct 31, 2010 at 12:53

lang-py

AltStyle によって変換されたページ (->オリジナル) /