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

Recommended Answers

All 4 Replies

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

Jeff

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.

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.