#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    2
    Rep Power
    0

    Talking TypeError: unhashable type: 'list'


    Hello...I'm new to this and need all the help I can get.....here is my problem.....
    **********************************************
    Enter command: grade_show
    Student's name: inewton

    Traceback (most recent call last):
    File "C:\Python27\grade1and2.py", line 88, in <module>
    process_input(user_input, dict)
    File "C:\Python27\grade1and2.py", line 35, in process_input
    dict.pop(marks)
    TypeError: unhashable type: 'list'
    ***********************************************
    and this is what I wrote:

    import sys

    def process_input(input, dict):

    students = dict.keys()
    marks = dict.values()

    (line 32 to 35)
    elif input == "grade_show":
    name = raw_input("Student's name: ")
    if name in students:
    dict.pop(marks)


    (line 84 to 88)
    user_input = ""
    while user_input != "done":
    user_input = raw_input("Enter command: ")

    process_input(user_input, dict)
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,905
    Rep Power
    481
    Code:
    import sys
    
    def process_input(input, DICT):  # usually replacing the name of a built in confuses readers.  It sure confused me.
    # would grades be a better name?  I prefer to describe the data in a name rather than the type.
    
        # students = DICT.keys()   # these lines aren't useful between 32 and 36 inclusive.
        # marks = DICT.values()    # in python 2 {}.values() and {}.keys() are lists.
    
        # (line 32 to 35)
    
        elif input == "grade_show":
            name = raw_input("Student's name: ")
            if name in DICT:
                GRADE = DICT.pop(name)  # Note that pop removes the item from the dictionary.
                # I've also stored the value for later use.
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    2
    Rep Power
    0

    Talking


    Originally Posted by b49P23TIvg
    Code:
    import sys
    
    def process_input(input, DICT):  # usually replacing the name of a built in confuses readers.  It sure confused me.
    # would grades be a better name?  I prefer to describe the data in a name rather than the type.
    
        # students = DICT.keys()   # these lines aren't useful between 32 and 36 inclusive.
        # marks = DICT.values()    # in python 2 {}.values() and {}.keys() are lists.
    
        # (line 32 to 35)
    
        elif input == "grade_show":
            name = raw_input("Student's name: ")
            if name in DICT:
                GRADE = DICT.pop(name)  # Note that pop removes the item from the dictionary.
                # I've also stored the value for later use.


    Thanks for the speedy reply.....After a long time tinkering with this problem I've found a solution and it worked out great.....


    #(line 32 to 35)

    elif input == "grade_show":
    name = raw_input("Student's name: ")
    if name in students:
    print(dict[name])


    Once again Thanks......

IMN logo majestic logo threadwatch logo seochat tools logo