Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python extract words from string with format

# credit to the Stack Overflow user in the source link
from ttp import ttp
import pprint
data = """
name=username1, age=1001
name=username2, age=1002
name=username3, age=1003
"""
template = "name={{ name }}, age={{ age }}"

parser = ttp(data, template)
parser.parse()
res = parser.result(structure="flat_list")
pprint.pprint(res)

# prints:
# [{'age': '1001', 'name': 'username1'},
#  {'age': '1002', 'name': 'username2'},
#  {'age': '1003', 'name': 'username3'}]
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #extract #words #string #format
ADD COMMENT
Topic
Name
3+6 =