I have this dictionary "properties" with a key livenessTests and in turn the livenessTests is a list of dictionaries. How do I add/append livenessTests to another dictionary json? - properties = {
-
-
'livenessTests': [
-
-
{
-
-
'name':'http' + '_' + 'livenesstest',
-
-
'testObject':'/default.html'
-
-
},
-
-
{
-
-
'name':'https' + '_' + 'livenesstest',
-
-
'testObject':'/default.html'
-
-
}
-
]
-
The resulting "json" directory should be something like - json : {
-
-
"acg": {
-
-
"id": "1-7KLGU.G19717",
-
-
"name": "Akamai Internal-1-7KLGU - 1-7KLGU.G19717"
-
-
},
-
-
"asmappings": [],
-
-
"cidrMaps": [],
-
-
"properties": {"livenessTests" : [{<contents from list above>},
-
{<contents from list above>}
-
]
-
-
}
I am trying this : - json['properties'] = []
-
-
for key in properties.keys():
-
print key
-
json['properties'].append(property[key])
-
But I am getting , - "livenessTests": [
-
{
-
"name": "http_livenessTest",
-
"testObject": "/default.html"
-
},
-
{
-
"name": "https_livenessTest",
-
"testObject": "/default.html"
-
},
so I am not getting the key 'properties' .
Can you tell me where I am wrong ?
1 1075
The same way you would add any other object.
myDict = {}
myDict[“myList”] = []
That would add an empty list, whose key is “myList”, to the dictionary “myDict”.
You could also use the dict “update” method, as follows:
myDict.update( myList: [] )
or this way:
myDict.update( {‘myList’: []} )
Although the second method is more appropriate to add several key/value pairs or for merging two dictionaries.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: ruari mactaggart |
last post by:
can this be tidied up ?
>>>verb={}
>>>verb=,,
,''],,,]
it is to create a dictionary entry with six empty lists of six items as
values.
or is it unnecesary ? They represent six tenses with...
|
by: beliavsky |
last post by:
Since Python does not have declarations, I wonder if people think it is
good to name function arguments according to the type of data structure
expected, with names like "xlist" or "xdict".
|
by: Raymond Hettinger |
last post by:
I would like to get everyone's thoughts on two new dictionary methods:
def count(self, value, qty=1):
try:
self += qty
except KeyError:
self = qty
def appendlist(self, key, *values):
try:
|
by: javuchi |
last post by:
I've been searching thru the library documentation, and this is the
best code I can produce for this alogorithm:
I'd like to return a dictionary which is a copy of 'another' dictionary
whoes...
|
by: Christoph Zwerschke |
last post by:
Ok, the answer is easy: For historical reasons - built-in sets exist
only since Python 2.4.
Anyway, I was thinking about whether it would be possible and desirable
to change the old behavior in...
|
by: Nico Grubert |
last post by:
Hi there,
I am looking for a way to sort a list containing dictionaries.
This is my example list:
I want to sort the list by dictionary's key 'from_datetime' so the
sorted list should be:
|
by: placid |
last post by:
Hi all,
Just wondering if anyone knows how to pop up the dialog that windows
pops up when copying/moving/deleting files from one directory to
another, in python ?
Cheers
|
by: vatamane |
last post by:
This has been bothering me for a while. Just want to find out if it
just me or perhaps others have thought of this too: Why shouldn't the
keyset of a dictionary be represented as a set instead of a...
|
by: GTXY20 |
last post by:
Hello;
I have the following dictionary:
d={1:, 2:, 3:, 4:}
I am having trouble removing the duplicate values in each of the keys value list, I need it so that:
d={1:, 2:, 3:, 4:}{/CODE]
|
by: ++imanshu |
last post by:
Hi,
Wouldn't it be nicer to have 'in' return values (or keys) for both
arrays and dictionaries. Arrays and Dictionaries looked so similar in
Python until I learned this difference.
Thanks,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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...
| |