Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8765437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:16:56+00:00 2026-06-13T16:16:56+00:00

fieldict(filename) reads a file in DOT format and returns a dictionary with the DOT

  • 0

fieldict(filename) reads a file in DOT format and
returns a dictionary with the DOT CMPLID, converted to an
integer, as the key, and a tuple as the corresponding value
for that key. The format of the tuple is:
(manufacturer, date, crash, city, state)

fieldict("DOT500.txt")[416]
  ('DAIMLERCHRYSLER  CORPORATION', datetime.date(1995, 1, 9), False, 'ARCADIA', 

so far, I have tried

from collections import defaultdict
import datetime

def fieldict(filename):
    with open(filename) as f:
        x=[line.split('\t')[0].strip() for line in f] #list of complaint numbers
        y= line.split('\t') #list of full complaints
        d={}
        for j in x:
            Y= True
            N= False
            d[j] = tuple(y[2],datetime.date(y[7]), y[6], y[12], y[13])   #dict with number of complaint as key and tuple with index as values
        return d

No luck… I think I am close..any help is greatly appreciated

EDIT: each complaint is formatted like this

'11\t958128\tDAIMLERCHRYSLER CORPORATION\tDODGE\tSHADOW\t1990\tY\t19941117\tN\t0\t0\tENGINE AND ENGINE COOLING:ENGINE\tWILMINGTON  \tDE\t1B3XT44KXLN\t19950103\t19950103\t\t1\tENGINE MOTOR MOUNTS FAILED, RESULTING IN ENGINE NOISE. *AK\tEVOQ\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tV\t\r\n'

Entry without character marks showing :

11  958128  DAIMLERCHRYSLER CORPORATION DODGE   SHADOW  1990    Y   19941117    N   0   0   ENGINE AND ENGINE COOLING:ENGINE    WILMINGTON      DE  1B3XT44KXLN 19950103    19950103        1   ENGINE MOTOR MOUNTS FAILED, RESULTING IN ENGINE NOISE.  *AK EVOQ    
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T16:16:57+00:00Added an answer on June 13, 2026 at 4:16 pm

    Looks like you want to make friends with the csv module, as this looks like tab formatted csv text. The csv.reader() has a .next() method which is called when you throw it in a for loop, so you can go line by line through the file.

    As a general tip, read PEP8, and use understandable variable names.
    With python, if it starts to feel hard that’s a good sign that there usually is a better way.

    import csv
    import datetime
    
    def _build_datetime(line)
        year_idx = x
        month_idx = y
        day_idx = z
        indexes = (year_idx, month_idx, day_idx)
    
        result_datetime = None
        if all(line[idx] for idx in indexes): # check that expected values are populated
            int_values = [int(line[idx]) for idx in indexes]
            result_datetime = datetime.date(*int_values)
        return result_datetime
    
    def format2dict(filename):
        complaints = {}
        with open(filename, "rb") as in_f:
            reader = csv.reader(in_f, delimiter='\t')
            complaint_id_idx = 0
            manufacturer_idx = 2
            crash_idx = x
            city_idx = 12
            state_idx = 13
    
            for line in reader:
                complaint_id = int(line[complaint_id_idx])
                data= (
                             line[manufacturer_idx], 
                             _build_datetime(line),
                             line[crash_idx],
                             line[city_idx],
                             line[state_idx],
                            )
    
                complaints[complaint_id] = data
        return complaints
    
    
    if __name__ == "__main__":
        formatted_data = format2dict("DOT500.txt")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It takes a file of 500 complaints, returns the number of the complaint as
I have a Silverlight 4 user control that calls a WCF service residing within
I have a script that will walk a system directory, and get the files
I already posted this for a help , but unfortunately none of them worked
I'm just learning Python & Django. (Thanks to everyone who contributes here -- it's
I have found several similar answers but I can't quite get why this is
How to disable spring log. When loading bean through xml its display spring log.
Possible Duplicates: Do Hibernate table classes need to be Serializable? What does Serializable mean?
For my homework assignment I need to write the body of this function, using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.