471,595 Members | 1,092 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,595 software developers and data experts.

Help with lists

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
1 1137
2,851 Expert Mod 2GB
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.

Similar topics

45 posts views Thread by Joh | last post: by
4 posts views Thread by Jacob H | last post: by
7 posts views Thread by Christian Christmann | last post: by
8 posts views Thread by rh0dium | last post: by
5 posts views Thread by dsmasters | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Anwar ali | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.