469,271 Members | 1,250 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

Help with lists

1
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?
Nov 27 '08 #1
1 1116
bvdet
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]
  3.  
  4. dd = dict(zip(ids,infoList))
  5. print dd
  6.  
  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)
Output:
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 zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.