[Solved] how to format the text-file data to a specific standard JSON [closed]

import json input=””‘ABCD=123=Durham EFGH=456=Nottingham IJKL=789=Peterborough”’ print(json.dumps({‘data’: [dict(zip((‘name’, ‘id’, ‘place’), l.split(‘=’))) for l in input.split(‘\n’)]})) This outputs: {“data”: [{“name”: “ABCD”, “id”: “123”, “place”: “Durham”}, {“name”: “EFGH”, “id”: “456”, “place”: “Nottingham”}, {“name”: “IJKL”, “id”: “789”, “place”: “Peterborough”}]} 2 solved how to format the text-file data to a specific standard JSON [closed]

[Solved] what is arr = [int(arr_temp) for arr_temp in input().strip().split(‘ ‘)] in python

You may want to look into python’s list comprehension. arr = [int(arr_temp) for arr_temp in input().strip().split(‘ ‘)] Let me answer this with an example, suppose you input : 1 3 4 29 12 -2 0 the input function reads this as a string The strip function eliminates whitespace from both ends of the string, The … Read more

[Solved] List elements to equal zero after 0 element

to add another options to all these good answers, another one with lambda: l = [4,3,3,2,1,0,1,2] f= lambda x,i : 0 if 0 in x[:i] else x[i] [f(l,i) for i in range(len(l))] output: [4, 3, 3, 2, 1, 0, 0, 0] 1 solved List elements to equal zero after 0 element

[Solved] Handlers in GAE

Assuming you’re posting to /compress.py, replace def z(self): with def post(self): That’ll get you to your next problem. As an aside, you’ll probably find it easier to take smaller steps. A small step in this case would be “can I hit a handler via URL and at least get a ‘hello world’ result?”. Maybe you’ve … Read more

[Solved] How to reduce redundant coding in java?

I assume that the isHttps variable check is there for a reason(?) and therefore the second cast should actually be HttpURLConnection, meaning there is a typo in the question? If so the most methods used in the question are available in the parent class URLConnection without a cast, but not all. Fortunately HttpsURLConnection is a … Read more

[Solved] Python, A string split into many pieces. How many pieces are in there?

You could get the length of the list of items after splitting: len(my_long_string.split(‘;’)) Alternatively, count the number of semicolons and add one: my_long_string.count(‘;’) + 1 The latter is probably faster if you don’t need to know what the items are, but only how many items there are. len is a function that returns the number … Read more

[Solved] No module named ‘PyPDF2._codecs’, even after already installed

This issue was only present in the PyPI distribution of PyPDF2==2.3.0 for a couple of hours. It was fixed with release 2.3.1. See #1011 for more details I’m the maintainer of PyPDF2. I’m sorry I caused some headaches. You can update PyPDF2 via: pip install PyPDF2 –upgrade solved No module named ‘PyPDF2._codecs’, even after already … Read more

[Solved] Renaming files that have specific format like text.* [closed]

You can use glob for get all files with pattern coord.* in your path and rename them with os.rename. import os import glob path=”Files/” for file in glob.glob(path+’coord.*’): f,s = file.split(‘.’,1) file_new = f+’N.’+s os.rename(file, file_new) First filenames: coord.1.txt coord.1.png After renaming: coordN.1.txt coordN.1.png 0 solved Renaming files that have specific format like text.* [closed]

[Solved] Basic Python variable function not working? [closed]

You are using the variable before it declaration. Carry your variable declaration at the top of the first print function For Example boy_name = “Bobby” print(“there was a boy named ” + boy_name + ” “) print(“there is a boy named timmy”) solved Basic Python variable function not working? [closed]

[Solved] How to sort a list and put it in absolute value

You can use the map and abs functions to accomplish this: In [1]: sorted(map(abs, lista)) Out[1]: [1, 2, 3, 5, 7, 8] To do this with the code you wrote, you can # The list defined above lista = [a,b,c,d] # Sorted from least to greatest absolute value sorted_abs_list = sorted(map(abs, lista)) # Sorted from … Read more