py wrote:
> I have some data (in a string) such as
>
> person number 1
>
> Name: bob
> Age: 50
>
>
> person number 2
>
> Name: jim
> Age: 39
>
> ...all that is stored in a string. I need to pull out the names of the
> different people and put them in a list or something. Any
> suggestio
On Nov 09, Dennis Benzinger wrote:
> Use the re module:
>
> import re
> your_data = """person number 1
>
> Name: bob
> Age: 50
>
>
> person number 2
>
> Name: jim
> Age: 39"""
>
> names = []
> for match in re.finditer("Name:(.*)", your_data):
> names.append(match.group(1))
> print names
py schrieb:
> I have some data (in a string) such as
>
> person number 1
>
> Name: bob
> Age: 50
>
>
> person number 2
>
> Name: jim
> Age: 39
>
> ...all that is stored in a string. I need to pull out the names of the
> different people and put them in a list or something. Any
> suggest
If you know the indices of where the data should be in your string, you
can use substrings... ie:
>>> stringy = " Happy Happy Cow, 50, 1234 Your Mom's House AllTheTime,USA "
>>> stringy[0:16]
' Happy Happy Cow'
If the data isn't set all the time (for example, and address doesn't
have a mandatory
If you know the indices of where the data should be in your string, you
can use substrings... ie:
>>> stringy = " Happy Happy Cow, 50, 1234 Your Mom's House AllTheTime,USA "
>>> stringy[0:16]
' Happy Happy Cow'
If the data isn't set all the time (for example, and address doesn't
have a mandatory