Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 2nd, 2005, 2:53 AM   #1
Gunman
Programmer
 
Gunman's Avatar
 
Join Date: Oct 2005
Posts: 56
Rep Power: 4 Gunman is on a distinguished road
How to ??

Hey i want to place a given name and number in this manner :

database = [["Gunman" , 1234],
                 ["Somethingelse" , 4321],
                 ["elsesomething" , 2341]]

If its possible could someone guide me on how to ? Thanks .
Gunman is offline   Reply With Quote
Old Nov 2nd, 2005, 4:47 AM   #2
andro
Professional Programmer
 
Join Date: Oct 2005
Location: California
Posts: 316
Rep Power: 4 andro is on a distinguished road
Send a message via AIM to andro
Use a dictionary object.

d = {'Gunman':1234, 'Somethingelse':4321, 'Anothershitgoose':5432}
andro is offline   Reply With Quote
Old Nov 2nd, 2005, 2:22 PM   #3
Dietrich
Professional Programmer
 
Dietrich's Avatar
 
Join Date: Feb 2005
Posts: 434
Rep Power: 4 Dietrich is on a distinguished road
Smile

This should work:
# create a list like [[name1, number1], ...]

list1 = []
print "(just press enter at name to break loop)"
while True:
    name = raw_input("enter name: ")
    if not name: break
    num = raw_input("enter number: ")
    try:
        number = int(num)
    except ValueError:
        num = raw_input("has to be a number: ")
        number = int(num)
    tuple1 = name, number
    list1.append(list(tuple1))
    print list1  # testing
    
print "result =", list1
__________________
I looked it up on the Intergnats!
Dietrich is offline   Reply With Quote
Old Nov 2nd, 2005, 11:27 PM   #4
Gunman
Programmer
 
Gunman's Avatar
 
Join Date: Oct 2005
Posts: 56
Rep Power: 4 Gunman is on a distinguished road
Thanx ! =))
Gunman is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:37 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC