-2

I've looked around on the internet but I haven't found anything that works. I want to turn dovah.csv into a dictionary for a translator.

Is there a way to specifically format it like this?

english_to_dovahzul = {
  'the': 'faal',
  'quick': 'nel',
  'brown': 'prun',
  'fox': 'ilit'
}

dovahzul_to_english = {v: k for k, v in.english_to_dovahzul.items()}
Son Truong
  • 13,661
  • 5
  • 32
  • 58

1 Answers1

0

You can try any example from below two:

example 1: with file handling:

with open(filename) as stream:
    result={}
    for item in stream.readlines()[1:]:
        line = item.strip().split()
        result.update({line[0]:line[2]})    #line[i] is column index to create dict
print(result)

example 2: with pandas.

import pandas as pd
df = pd.read_csv(filename, sep='\t', lineterminator='\r')
result = dict(zip(df["English Word"],df["Dragon Translation"]))  #df['column_name'] is column name to create dict
print(result)
Chandella07
  • 2,089
  • 14
  • 22