Read a text file into a dictionary

Pagina: 1
Acties:
  • 357 views

Onderwerpen

Vraag


Acties:
  • 0 Henk 'm!

  • Yeeeesh
  • Registratie: Oktober 2019
  • Laatst online: 16-12-2024
Python

What I need is a dictionary with the following information:
YAHOO:YHOO
GOOGLE INC:GOOG
HARLEY-DAVIDSON=HOG

This is all in a textfile, I need to open this and get it into a dictionary which I can use later to get something out. The problem is (as me being a beginning programmer) that I dont know exactly how to do it.

This is what I made so far, but can't figure out how to make it work:

d={}
def(tickets):
infile=open("tickets","r")
for row in infile:
d(row(0)) = (row(1))

and it give an error: Can't assign to function call.
What did I do wrong and how can I make it work?

Alle reacties


Acties:
  • 0 Henk 'm!

  • RobIII
  • Registratie: December 2001
  • Niet online

RobIII

Admin Devschuur®

^ Romeinse Ⅲ ja!

(overleden)
Neem even onze quickstart door en open dan een nieuw topic gewoon in 't Nederlands. En gebruik a.u.b. code tags als je code post. Hou er rekening mee dat we hier niet je huiswerk gaan doen; we helpen je hooguit in de juiste richting ;) We willen dus wel zien wat je zélf al geprobeerd, gezocht, gevonden hebt etc.

[ Voor 27% gewijzigd door RobIII op 08-10-2019 19:41 ]

There are only two hard problems in distributed systems: 2. Exactly-once delivery 1. Guaranteed order of messages 2. Exactly-once delivery.

Je eigen tweaker.me redirect

Over mij


Dit topic is gesloten.