954,546 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

search pattern in a file and create dictionary as you search

i know how to create a dictionary but how do i search for a pattern in a file and then create a dictionary based on the search

axn
Light Poster
39 posts since Sep 2007
Reputation Points: 10
Solved Threads: 0
 

The problem is a little unclear. What should the contents of the dictionary look like?

Jeff

jrcagle
Practically a Master Poster
608 posts since Jul 2006
Reputation Points: 92
Solved Threads: 156
 

contents of dictionary should have first name, last name, age and so on as the keys.
if i find john in the file populate that in the dict. as the value for first name. find his age and do the same. i hope this helps.

axn
Light Poster
39 posts since Sep 2007
Reputation Points: 10
Solved Threads: 0
 

It would be better to use an existing tool like Metakit or SQLite. This pages show how it would be done with Metakit http://www.equi4.com/metakit/python.html

woooee
Nearly a Posting Maven
2,454 posts since Dec 2006
Reputation Points: 777
Solved Threads: 714
 

it would be better to show a sample input file, your expected output as well.
to search in a file. just an example...considering i don't know what your file structure is like.

for line in open("file"):
   if "john" in line:
      d['john'] = line
ghostdog74
Junior Poster
156 posts since Apr 2006
Reputation Points: 75
Solved Threads: 44
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You