How to change the values of user-inputted strings that act as keys in a nested dictionary pulled from a JSON

Advertisements I’m sorry for the crazy title. I’m new to programming and have no idea what I’m doing. I’m making a weight tracker that saves data to a JSON. The data is a nested dictionary that supposed to look like: { "Dates": { "11/11/11": { "Morning": 500, "Night": 502 } } } I’ve been trying… Read More How to change the values of user-inputted strings that act as keys in a nested dictionary pulled from a JSON

Access nested element value in foreach xsl

Advertisements I use foreach loop <xsl:for-each select="catalog/cd[artist[@id=’2′]]"> to loop in cd. Then, I want to get title1 tag value <title1>Unchain my heart</title1> using title/title1 But , output nothing. <?xml version="1.0" encoding="UTF-8"?> <catalog> <cd> <title>Red</title> <artist>The Communards</artist> <country>UK</country> <company>London</company> <price>7.80</price> <year>1987</year> </cd> <cd> <title> <title1>Unchain my heart</title1> <title2>Unchain my heart 2</title2> </title> <artist id=’2′>Joe Cocker</artist> <country>USA</country>… Read More Access nested element value in foreach xsl

Python for loop through nested dictionary question?

Advertisements Trying to loop through a nested dictionary and want to store values into name, age and occupation. Without manually creating those variables within the for loop. Is this even possible? Just trying to create cleaner looking code. Thank you. people = { 1: {"name": "Simon", "age": 20, "occupation": "Data scientist"}, 2: {"name": "Kate", "age":… Read More Python for loop through nested dictionary question?

Flatten column within data frame containing nested dictionaries and lists

Advertisements I have a pandas dataframe with 8 columns, one of which is made up of cells containing nested dictionaries and lists in the following format: {‘x1’: {‘y1’: [‘z1’, ‘z2’], ‘y2’: [‘z3’, ‘z4’, ‘z5’]}, ‘x2’: {‘y1’: [‘z6’, ‘z7’, ‘z8’], ‘y2’: [‘z9′, z10’]}} How can I transform this column so that the x-variables are melted with… Read More Flatten column within data frame containing nested dictionaries and lists

Extracting data from nested dict in ansible with conditional checks in the list?

Advertisements I’m stuck with the following issue. My JSON data looks like this: [ { "clusters":[ { "id":"1", "name":"cluster1" }, { "id":"2", "name":"cluster2" } ], "tag":"a" }, { "clusters":[ { "id":"3", "name":"cluster2" } ], "tag":"b" } ] What I am trying to do is extracting the tag values which are connected to a certain cluster… Read More Extracting data from nested dict in ansible with conditional checks in the list?

Trying to push the contents of objects nested inside objects to an array (JavaScript)

Advertisements When having objects nested inside objects I can’t loop through them with a regular for in loop. I googled and found I have to make a recursive function that would check if the property is an object. I wrote a recursive function like this: ` function isObject(value){ return (typeof(value)===’object’); } “ function listToArray(list){ let… Read More Trying to push the contents of objects nested inside objects to an array (JavaScript)

How can I make this programme format the string properly? PHP – Nested For Loop

Advertisements <?php $list = [‘a’, ‘b’, ‘c’]; $count = [1, 3, 5]; function stringFormatter($c, $i) { return "Char is $c & Int is $i"; } for ($i = 0; i < $list; $i++) { for ($j = 0; $j < $count; $j++) { $string = stringFormatter($list[$i], $count[$j]); print $string; } } ?> This is sample… Read More How can I make this programme format the string properly? PHP – Nested For Loop