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 > suggestions...besides doing data.index("name")...over and over? > > thanks! >
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 Bye, Dennis -- http://mail.python.org/mailman/listinfo/python-list