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

  • Home
  • SEARCH
  • 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 8748619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:33:23+00:00 2026-06-13T12:33:23+00:00

hey everyone the question is like this, this is homework question to be honest

  • 0

hey everyone the question is like this, this is homework question to be honest but I am just stuck and its been forever.
My question is, since the city has different index positions in each line how can we iterate line by line and return city names into a list?
(any help that can get me started will be appreciated I am not being lazy I really did work on this for couple hours already)

citylist(filename)  reads a file in the DOT format
      and returns a list of city names, one for each line in 
      the file.  The DOT format may have trailing spaces on 
      the city name;  make sure citylist creates a list of 
      city names with trailing spaces removed (easy using
      Python's strip() method).  Two test cases are shown 
      below, for lines at index 3 and 347.

citylist("DOT500.txt")[3]
  'TUCSON'

citylist("DOT500.txt")[347]
  'NORTH VILLE'

and below is the DOT file(part of it)

1   958164  TOYOTA MOTOR CORPORATION    TOYOTA  LAND CRUISER    1994        19941223    N   0   0   SERVICE BRAKES, HYDRAULIC:ANTILOCK  ARNOLD          CA  JT3DJ81W8R0 19950103    19950103            ABS SYSTEM FAILURE, AT 20MPH.  TT   EVOQ                                                                                                    V   

2   958156  TOYOTA MOTOR CORPORATION    TOYOTA  PASEO   1994    Y   19941226    N   0   0   PARKING BRAKE:CONVENTIONAL  SAN JOSE        CA  JT2EL45U5R0 19950103    19950103        1   PARKED ON FLAT SURFACE EMERGENCY BRAKING ENGAGED VEHICLE ROLLED REARWARD.  TT   EVOQ                                                                                                    V   

3   958124  TOYOTA MOTOR CORPORATION    TOYOTA  COROLLA 1994    Y   19941128    N   0   0   AIR BAGS:FRONTAL    PHOENIX         AZ      19950103    19950103            UPON FRONTAL COLLISION, AIR BAG FAILED TO DEPLOY. VEHICLE CLASSIFIED AS TOTALED. PLEASE DESCRIBE DETAILS.  TT   EVOQ                                                                                                    V   

4   958122  NISSAN NORTH AMERICA, INC.  NISSAN  MAXIMA  1994        19950103    N   0   0   SUSPENSION  TUCSON          AZ  JN1HJ01F4RT 19950103    19950103            THE STRUT WAS BAD THERE IS A NOISE ON THE PASSENGER SIDE DOOR AND THE ENGINE LIGHT MALFUNCTION.  TT EVOQ                                                                                                    V   

5   958122  NISSAN NORTH AMERICA, INC.  NISSAN  MAXIMA  1994        19950103    N   0   0   ENGINE AND ENGINE COOLING:ENGINE    TUCSON          AZ  JN1HJ01F4RT 19950103    19950103            THE STRUT WAS BAD THERE IS A NOISE ON THE PASSENGER SIDE DOOR AND THE ENGINE LIGHT MALFUNCTION.  TT EVOQ                                                                                                    V   

6   958247  NISSAN NORTH AMERICA, INC.  NISSAN  PATHFINDER  1994            N   0   0   SUSPENSION:FRONT    ABINGDON        MD      19950103    19950103            FRONT TIRES SHOW EXCESSIVE WEAR AND STEEL BELTS. NISSAN IS OFFERING TO REPLACE TWO TIRES.  TT   EVOQ                                                                                                    V   

7   958143  FORD MOTOR COMPANY  FORD    MUSTANG 1991        19941119    Y   0   0   SEATS:FRONT ASSEMBLY:POWER ADJUST   PENSICOLA       FL      19950103    19950103            DRIVER SIDE POWER SEAT CAUGHT FIRE.  TT EVOQ                                                                                                    V   

8   958141  DAIMLERCHRYSLER CORPORATION CHRYSLER    NEW YORKER  1989        19950103    N   0   0   POWER TRAIN:AUTOMATIC TRANSMISSION  LEVITTOWN       NY  1C3BC4639KD 19950103    19950103        2   TRANSMISSION NOT SHIFTING OUT OF 2ND GEAR, WENT INTO LIM MODE/TRANSMMION NOT SHIFTING THEN JUMPED OUT OF GEAR. *AK  EVOQ                                                                                                    V   

9   958128  DAIMLERCHRYSLER CORPORATION DODGE   SHADOW  1990    Y   19941224    N   0   0   SERVICE BRAKES, HYDRAULIC:ANTILOCK  WILMINGTON      DE  1B3XT44KXLN 19950103    19950103        1   ABS: EXPERIENCED ANTI-LOCK BRAKE FAILURE/EXTENDED STOPPING DISTANCE, RESULTING IN AN ACCIDENT, IMPACT 12:00 POSITION SPEED, 20 MPH.  TT EVOQ                                                                                                    V   

10  958128  DAIMLERCHRYSLER CORPORATION DODGE   SHADOW  1990    Y   19940412    N   0   0   SUSPENSION:FRONT    WILMINGTON      DE  1B3XT44KXLN 19950103    19950103        1   MISALIGNMENT, CAUSING VEHICLE TO VEER TO THE CENTER.  *AK   EVOQ                                                                                                    V   

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                                                                                                    V   

12  958168  GENERAL MOTORS CORP.    CHEVROLET   SUBURBAN    1995    Y   19950101    N   0   0   POWER TRAIN:AUTOMATIC TRANSMISSION:GEAR POSITION INDICATION (PRNDL) SHAFTFBURG      MI      19950103    19950103            VEHICLE ROLLED DOWN HILL WHILE IN PARK, AND INTO A TREE.  TT    EVOQ                                                                                                    V   

13  958169  GENERAL MOTORS CORP.    GEO METRO   1995    Y   19941225    N   1   0   SERVICE BRAKES, HYDRAULIC:FOUNDATION COMPONENTS NORFOLK         VA      19950103    19950103            BRAKES WOULD NOT WORK ON SEVERAL OCCASIONS, LAST INSTANCE RESULTED IN AN ACCIDENT.  TT  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-13T12:33:25+00:00Added an answer on June 13, 2026 at 12:33 pm

    In the general case, this would be really, really hard. But we can see if they’ve made it any easier for us. We can read in a line and look at it:

    In [31]: first_line = open("toyota.dot").readline()
    
    In [32]: print repr(first_line)
    '    1\t958164\tTOYOTA MOTOR CORPORATION\tTOYOTA\tLAND CRUISER\t1994\t\t19941223\tN\t0\t0\tSERVICE BRAKES, HYDRAULIC:ANTILOCK\tARNOLD      \tCA\tJT3DJ81W8R0\t19950103\t19950103\t\t\tABS SYSTEM FAILURE, AT 20MPH.  TT\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\n'
    

    See all those \t symbols? We’re in luck — the columns are separated by tabs! So one way is to use the .split() method on the lines to break them into columns:

    In [33]: first_line.split("\t")
    Out[33]: 
    ['    1',
     '958164',
     'TOYOTA MOTOR CORPORATION',
     'TOYOTA',
     'LAND CRUISER',
     '1994',
    [... etc ...]
     '\n']
    

    and we can then extract columns:

    In [34]: first_line.split("\t")[11]
    Out[34]: 'SERVICE BRAKES, HYDRAULIC:ANTILOCK'
    
    In [35]: first_line.split("\t")[12]
    Out[35]: 'ARNOLD      '
    

    and get rid of the spaces.

    In [36]: first_line.split("\t")[12].strip()
    Out[36]: 'ARNOLD'
    

    You can use the

    with open("toyota.dot") as data:
        for line in data:
            parts = line.split("\t")
    

    pattern to iterate over the lines, and the rest you should be able to piece together.

    [Aside: I’d actually use a csv.reader with delimiter="\t", but that’s probably a little beyond what the teacher is after.]

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey Everyone, This question seems really silly to me, but I can't for the
Hey everyone quick question, I know this sounds strange to do in javascript but
Hey everyone, just a quick thing, I have the hex to integer working, but
Hey everyone, this seems like it should be a simple one; I really hope
http://jsfiddle.net/kCMvt/ Hey everyone. I made this jQuery page for a mobile phone, but the
Hey Everyone, Sorry to bother you with this, but I'm having an issue with
Hey everyone, this is an EXTREMELY beginner question, and I'm somewhat ashamed I don't
Hey there, everyone. A really random question, but I'm looking to get into some
Hey everyone, here is the site in question: http://www.myvintagesecret.com/ I have a bunch of
Hey everyone. I'm not big into UI programming so this may be an easy

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.