Issue in iterating over Python dictionaries with lists and sub-dictionaries

I have a data structure I have read from a file which looks like below – data = {"test":[‘[{"Day":"Monday","Device":"Android","Data":[1, 2, 3]}, {"Day":"Tuesday","Device":"Iphone","Data":[10, 20, 30]}]’]} I am trying to access the elements of the structure like below, peeling off one by one – value = data["test"] print(value) #[‘[{"Day":"Monday","Device":"Android","Data":[1, 2, 3]}, {"Day":"Tuesday","Device":"Iphone","Data":[10, 20, 30]}]’] value1 = value[0]… Read More Issue in iterating over Python dictionaries with lists and sub-dictionaries

String.data(using: .utf8): What is the effect of having the argument specified?

From an video-tutorial, which I’m currently using for learning: let data = """ { "customers": [ { "firstname": "John", /* … */ } ] } """.data(using: .utf8) What does the .data-method? From what I read in the documentation, I would say it loads the data into a buffer. But what’s the argument with the label… Read More String.data(using: .utf8): What is the effect of having the argument specified?

Can a bash script extract name, version number and extension from a list of filenames

I am having trouble creating a Bash script that will extract application name, version number and possible extension from a list of filenames such as: name-of-application-1-v1.2.3.AppImage app-name2-V999.2.31.AppImage another-application-v123.456.789 yet-another-example-4-V0.0.1.extA For the above examples, the application names would be: name-of-application-1 app-name2 another-application yet-another-example-4 The version numbers would be: 1.2.3 999.2.31 123.456.789 0.0.1 The extensions would be:… Read More Can a bash script extract name, version number and extension from a list of filenames

How to make changes in XML file in Python

I have a xml file MC.xml contents of which are <?xml version="1.0" encoding="UTF-8"?> <MCOO type="list"> <AAA> <Active value="True" li="True" mv="True"/> <Plot value="True" li="False" mv="False"/> <Color value="#990000"/> </AAA> <BBB> <Active value="True" li="True" mvl="True"/> <Plot value="True" li="False" mvl="False"/> <Color value="#990000"/> </BBB> <CCC> <Active value="True" li="False" mv="True"/> <Plot value="False" li="False" mv="False"/> <Color value="#990000"/> </CCC> </MCOO> I have a… Read More How to make changes in XML file in Python

Adding a Substring to a String without knowing the position

I want to add a char(newline) to a String by specifiying the location with a Substring. Is that possible in Python or Java? Here’s how I imagine it, Newline is added to the String at the position between two arrays ‘],’: str = [[a,b,c], [d,e,f]] result = addString(str, ‘],’, ‘\n’) print(result) Output: [[a,b,c], [d,e,f]] >Solution… Read More Adding a Substring to a String without knowing the position

Use .find() on a JSON file to get a a string with a specific keyterm

I’m trying to use array.find() to get the first JSON string that contains amogus. I’ve tried to read the JSON file using fs then using JSON.parse() to make it readable. However, I can’t seem to get it to do what I want it to do. JSON file: {stuff: ["hosds29083", "amogus1208", "amogus1213"] desired output: amogus1208 Thanks.… Read More Use .find() on a JSON file to get a a string with a specific keyterm