By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,923 Members | 1,443 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,923 IT Pros & Developers. It's quick & easy.

Help with lists

P: 1
userid = form["userid"].value

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

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?
Nov 27 '08 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 2.5K+
P: 2,851
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:
Expand|Select|Wrap|Line Numbers
  1. ids = ['studenta', 'studentb', 'studentc']
  2. infoList = [75,80,90]
  4. dd = dict(zip(ids,infoList))
  5. print dd
  7. for id in ['studenta', 'studentb', 'studentc', 'studentd']:
  8.     info = dd.get(id, "No information is available")
  9.     print "Information for student %s: %s" % (id, info)
Expand|Select|Wrap|Line Numbers
  1. >>> {'studentc': 90, 'studentb': 80, 'studenta': 75}
  2. Information for student studenta: 75
  3. Information for student studentb: 80
  4. Information for student studentc: 90
  5. Information for student studentd: No information is available
  6. >>> 
Nov 28 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.