| | |
Manipulating dictionaries
![]() |
•
•
Join Date: Oct 2008
Posts: 13
Reputation:
Solved Threads: 0
Here I go with yet another of my don't-get-the-syntax-problems. For some reason I tend to get a lot more from putting a question here than reading through a few dozen pages of documentation, which I have once again done.
Say I have a dictionary as a basic data structure in a program. I'd like to be able - as a user input - to add additional keys to existing values and additonal values to existing keys. Everything I read feels like it comes almost to the point of explaining it and then says something like "And that's all of it".
Any hints would be great!
Say I have a dictionary as a basic data structure in a program. I'd like to be able - as a user input - to add additional keys to existing values and additonal values to existing keys. Everything I read feels like it comes almost to the point of explaining it and then says something like "And that's all of it".
Any hints would be great!
You can't necessarily "add additional keys to existing values", unless you simply meant add additional key/value pairs to the existing dictionary. Here's some examples of adding elements to a dictionary:
python Syntax (Toggle Plain Text)
>>> d = {'a':1, 'b':2, 'c':3} >>> d['d'] = 4 >>> d['a'] = [ d['a'], 12, 13 ] >>> d['e'] = [] >>> d['e'].append('foobar') >>> d {'a': [1, 12, 13], 'c': 3, 'b': 2, 'e': ['foobar'], 'd': 4} >>>
![]() |
Similar Threads
- IE6/IE7 unexpectedly drops the PHP Session ID cookie (PHPSESSID) (PHP)
- Scanning a string? (Python)
- Future of programming language? (Computer Science)
Other Threads in the Python Forum
- Previous Thread: Problem with MakeMenuBar()
- Next Thread: Python Help - decimal to binary program
| Thread Tools | Search this Thread |
abrupt ansi anti apache approximation array assignment avogadro backend beginner binary book builtin calculator character code converter countpasswordentry curved customdialog dan08 dictionaries dictionary dynamic examples exe file float format function gnu graphics gui heads homework import inches input java launcher library line lines linux list lists loop mouse mysql mysqlquery number numbers numeric output parsing path phonebook plugin pointer port prime programming progressbar projects py2exe pygame pysimplewizard python random recursion redirect scrolledtext software statictext statistics string strings sum table terminal text textarea thread threading time tlapse trick tricks tuple tutorial twoup ubuntu unicode urllib urllib2 variable wordgame write wxpython xlib






