473,394 Members | 1,951 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How do i append data to a list contained inside a dict ?

Jory R Ferrell
I need to assign lists containing class objects to a key (so i can create var names for a user defined numb of objts). I tried appending to the key of a list and couldnt get it to work. How would i manipulate objects when i rely on a dictionary to refer to them? :/
Jan 23 '12 #1

✓ answered by bvdet

You can easily modify dictionary values by reassignment or manipulation of the value or its attributes.
Expand|Select|Wrap|Line Numbers
  1. >>> dd = {"a": 123, "b": 456}
  2. >>> dd["a"] += 321
  3. >>> dd
  4. {'a': 444, 'b': 456}
  5. >>> dd = {"a": [1,2,3], "b": [4,5,6]}
  6. >>> dd["a"].append(4)
  7. >>> dd
  8. {'a': [1, 2, 3, 4], 'b': [4, 5, 6]}
  9. >>> 

3 1889
bvdet
2,851 Expert Mod 2GB
You can easily modify dictionary values by reassignment or manipulation of the value or its attributes.
Expand|Select|Wrap|Line Numbers
  1. >>> dd = {"a": 123, "b": 456}
  2. >>> dd["a"] += 321
  3. >>> dd
  4. {'a': 444, 'b': 456}
  5. >>> dd = {"a": [1,2,3], "b": [4,5,6]}
  6. >>> dd["a"].append(4)
  7. >>> dd
  8. {'a': [1, 2, 3, 4], 'b': [4, 5, 6]}
  9. >>> 
Jan 23 '12 #2
Hold one....maybe I wrote the code up wrong.... :P
Jan 23 '12 #3
Yeh...I wrote it up wrong somehow yesterday....
ty
Jan 23 '12 #4

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

Similar topics

3
by: Jonathan Buckland | last post by:
Can someone give me an example how to append data without having to load the complete XML file. Is this possible? Jonathan
0
by: Winterminute | last post by:
I am binding the results of a database query to a DataList using the following code: SqlDataAdapter myCommand = new SqlDataAdapter("SELECT * FROM _Hardware_Configurations", myConnection);...
2
by: Steve Lloyd | last post by:
Hi there, I have a set of products each of which has attributes (color size etc), is it possible to use a data list or repeator to display all the items and provide combo box with a unique set...
1
by: Shahid Saleem | last post by:
Dear Members I want to generate a Template using DataList and i want to user Grid control in the item template, is it possible. if yes need some explanation regarding data binding of grid...
1
by: Shahid Saleem | last post by:
Dear Members I am using a data list , in the item template i have used a data grid with template column (CheckBox) and a button named sumbit. I want to get the data grid selected rows(Makred...
10
by: HYRY | last post by:
I have the following questions, I am using Python 2.4.2 19167152 #1 11306608 #1 1. the address of a.append and list.append is different, can I get the address of...
1
by: Milan Mehta | last post by:
I am a newbie to MS Access. Please bear with me for such question. I have a table1 in Database1. I need to append data from table2 in Database2 to table1 of Databases1. How can I do that ? TIA...
20
by: Pat | last post by:
I know it's not "fair" to compare language features, but it seems to me (a Python newbie) that appending a new key/value to a dict in Python is awfully cumbersome. In Python, this is the best...
3
by: premMS143 | last post by:
How to append Data to an existing Excel file? means, I'm using VB as front end & once I exported the data to Excel file & saved it as 'ABC.xls'. Now, the question/doubt is; I addded some more...
4
by: Busbait | last post by:
Hi, I have the following code which works fine in MS Access 2007. It export current access form records to an excel sheet: DoCmd.OutputTo acOutputQuery, "RunQuery", acFormatXLSX, , True Is...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...

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.