473,543 Members | 2,348 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with lists

1 New Member
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 1168
bvdet
2,851 Recognized Expert Moderator Specialist
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

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

Similar topics

45
2980
by: Joh | last post by:
hello, i'm trying to understand how i could build following consecutive sets from a root one using generator : l = would like to produce : , , , ,
4
5435
by: Jacob H | last post by:
Hello list... I'm developing an adventure game in Python (which of course is lots of fun). One of the features is the ability to save games and restore the saves later. I'm using the pickle module to implement this. Capturing current program state and neatly replacing it later is proving to be trickier than I first imagined, so I'm here to...
7
1797
by: Christian Christmann | last post by:
Hi, in the past I always appreciated your help and hope that you also can help me this time. I've spent many many hours but still can't solve the problem by myself and you are my last hope. I've a program which is using self-written double-linked lists as a data structure. The template list consists of list elements and the list itself...
1
2041
by: prime80 | last post by:
I'm building a project database to keep track of the various engineering projects ongoing in our department. These projects will be grouped by priority (=High, Medium, Low) and ranked within the priority (=1,2,3,etc.). What I'd like for it to do is automatically update rankings when a project rank is changed, a new project comes in, or a...
8
1673
by: rh0dium | last post by:
Hi all, I am using python to drive another tool using pexpect. The values which I get back I would like to automatically put into a list if there is more than one return value. They provide me a way to see that the data is in set by parenthesising it. This is all generated as I said using pexpect - Here is how I use it.. child =...
5
2050
by: dsmasters | last post by:
Hey there, I have been piecing this menu system together from a couple of different sources and can almost see the end the of the tunnel. This is based on the Suckerfish Dropdowns which then incorporates an iframe to allow the menu to be over the form. (See links) http://www.htmldog.com/articles/suckerfish/dropdowns/...
2
3555
by: Cox | last post by:
Hello: My address jsmith435@cox.net is subscribed to at least the PHP General mailing list. I have for days now been trying to unsubscribe from all PHP mail lists. I have followed the instructions posted on the php.net web site but all my e-mails go unresponded to. I've tried contacting the webmaster as well as the admin address posted...
0
1168
by: bharathitm | last post by:
I'm working on regular expressions to parse html tags into the wiki syntax. i.e. for example, if i encounter text like - some <bmore </ btext, my regular expression should be able to convert that to some 'more' text. Simple things like the above, i was able to write but the real problem lies when it comes to parsing lists and tables. For...
0
1017
kaptaineaux
by: kaptaineaux | last post by:
Hi, What I am trying to do is update a field in list programmatically using a webpart. What I do is I get the context of the site, then all lists of type Events. For each End field that is apart of those lists, I want to make that field required. The problem I'm running into, on Update(), the change does not take. I have no idea what's...
3
1249
by: Qbert16 | last post by:
Hi, I'm quite new to python and am looking for help with lists inside lists This is an example I'm trying to do. I have the following thesaurus set... thesaurus = , ] The real one for my assignment has many more lists inside lists, but I am trying to keep it simple to find the solution.
0
7590
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7347
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7688
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5885
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3391
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3391
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1817
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
968
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
636
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.