Help with lists

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rca31
    New Member
    • Nov 2008
    • 1

    Help with lists

    userid = form["userid"].value

    for entry in data:
    if userid != entry[0]:
    print "<p> No grades available. </p>"
    else:
    print


    entry[0] = [studenta, studentb, studentc, etc...]
    entry[1] = [75,80,90, etc...]

    I'm trying to create a web form where a user can type in their userid (studenta) and then the program will only display their own information. For example, studenta:75. However, if the username is not on file, it displays "No grades available".

    Can anyone give me a hand?
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Please use code tags around the code you post. Like this:
    [CODE].....code goes here.....[/CODE]

    A dictionary and dictionary method get() are well suited for this task. Example:
    Code:
    ids = ['studenta', 'studentb', 'studentc']
    infoList = [75,80,90]
    
    dd = dict(zip(ids,infoList))
    print dd
    
    for id in ['studenta', 'studentb', 'studentc', 'studentd']:
        info = dd.get(id, "No information is available")
        print "Information for student %s: %s" % (id, info)
    Output:
    Code:
    >>> {'studentc': 90, 'studentb': 80, 'studenta': 75}
    Information for student studenta: 75
    Information for student studentb: 80
    Information for student studentc: 90
    Information for student studentd: No information is available
    >>>

    Comment

    Working...