| | |
Manipulating dictionaries
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
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
Views: 460 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for Python
address anydbm app bash beginner bits calling class code conversion coordinates copy dan08 dictionary directory dynamic edit examples excel feet file float format ftp function generator gui halp homework http i/o images import info input ip itunes java keycontrol line linux list lists loop maintain millimeter mouse newb number numbers output panel parsing path port prime print program programming projects py-mailer py2exe pygame pyqt python queue random rational recursion recursive scrolledtext server smtp split ssh statictext string strings sudokusolver table terminal text thread threading time tkinter tlapse tuple tutorial type ubuntu unicode update urllib urllib2 variable whileloop windows write wxpython






