Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 27th, 2003, 01:53 PM
FLNHST FLNHST is offline
404 Error
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2002
Location: http://hester.dns2go.com
Posts: 18 FLNHST User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 52 m 3 sec
Reputation Power: 0
how to add?

i create a dictionary (i think thats the name):

a = {"nr1":"Number 1"}

but how do i add new keys?

Reply With Quote
  #2  
Old September 27th, 2003, 02:08 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,537 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 17 m 47 sec
Reputation Power: 68
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
Adding keys to a dictionary Python is very easy , it's allot like assigning a vaule to a variable i.e. dictionary[key] = value would add a key to the dictionary with a value

Here's a small example of this from Python's shell..

>>> dictionary = {'one': 1}
>>> dictionary
{'one': 1}
>>> dictionary['two'] = 2
>>> dictionary
{'two': 2, 'one': 1}

Note: dictionaries are unordered and don't need to be for obvious reasons

Have fun,
Mark.
__________________
programming language development: www.netytan.com Hula


Reply With Quote
  #3  
Old September 27th, 2003, 02:11 PM
FLNHST FLNHST is offline
404 Error
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2002
Location: http://hester.dns2go.com
Posts: 18 FLNHST User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 52 m 3 sec
Reputation Power: 0
thanks!

Reply With Quote
  #4  
Old September 29th, 2003, 10:18 AM
cvchen cvchen is offline
Hi, I'm Calvin
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: LosAngeles, SanDiego, Houston
Posts: 50 cvchen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 7 sec
Reputation Power: 10
oh wow... that's a better than the way that i've been doing it.

i've been doing this:

dictionary.update({'two':2})

well, ya learn something new everyday...

Reply With Quote
  #5  
Old September 29th, 2003, 02:55 PM
percivall percivall is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 133 percivall User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 10
Also, if you want to create a dictionary with string keys, you can write:
Code:
>>> dict(alfa="a", beta="b", gamma="g")
{'beta': 'b', 'alfa': 'a', 'gamma': 'g'}

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > how to add?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap