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 8545431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:47:22+00:00 2026-06-11T12:47:22+00:00

So I am creating a dictionary with the values given in a csv file

  • 0

So I am creating a dictionary with the values given in a csv file and now I am trying to have an input where you type in a key and it will check the dictionary for that key and then return the value. I am having trouble implementing this but this is what I have and I believe I should be using d.get() but I’m not 100 percent sure.

import csv

dictionary = []

line = 0
reader = csv.reader(open("all.csv", "rb"), delimiter = ",")

header = reader.next()

for column in reader:
    line = line + 1

    dictionary.append({column[0]:column[2]})

print dictionary

check = raw_input("Enter word in dictionary to get its value: ")

print dictionary.get(check, "This word doesnt exist in the dictionary")
  • 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-11T12:47:23+00:00Added an answer on June 11, 2026 at 12:47 pm
    dictionary = []
    

    That is not a dictionary, it is a list. Thus, it doesn’t have a get method.

    What you want to do is initialize the dictionary like this:

    dictionary = {}
    

    (Note the curly braces rather than the square brackets). Also change the assignment line to this:

        dictionary[column[0]] = column[2]
    

    At that point, your program should work.

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

Sidebar

Related Questions

The Background: I have been creating a script that based on input csv's that
I have a scenario where I have a propertybag of key/values that would look
I have a simple dictionary: {keyy:{key: value, cey: value}, kaye:{key: value}} That I want
Creating liquid layouts is an immense pain. Now, I totally understand that tables should
Creating a server-side socket will fail if I'm trying to use the same port
Hopefully I'm not missing something obvious... I'm creating a function that will ease in
I have a dictionary that I've converted to a list so I can sort
working on creating an XML file with some data using Python. I am trying
I'm trying to test some application logic that is dependent on the Values property
I have a file with a list of paired entries (keys) that goes like

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.