Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
What code should I use to write a program that stores the following content in a variable?
I cannot use an external file.
{'title':'El Más Allá','aka':'E tu vivrai nel terrore - Laldilà','director':'Lucio Fulci', 'year':1981, 'country':'Italia'}
just store it in a dict like this
import json
instr = input(">>>")
myDict = json.loads(instr)
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 days ago.
Improve this question
how I can How can I do it the other hay around, for example, I want my program to be able to ask me for the value of r1 and vote for the level like this Input is 10000000 and the result is 10001, which would be the level
nivel = 10001 - 1
re = nivel**2
re1 = re *10
print (f"\nnivel 7014 : {re1}")
I don't know how I can solve it
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I am trying to separate all the images from the following string.
how can I get a list of images that start with "comp1/img_" and are either split by a "," or a ";"
/*jsonp*/jsonresp({"img_set":"comp1/img_23434;comp1/img_3243r43r,comp1/img_o43nfjr;comp1/img_wjfno43,comp1/img_nrejfner;comp1/img_jrenckerjv,comp1/img_23434k;comp1/img_rkfnk4n"},"fknreff\",");
so I would end up with a list like...
comp1/img_23434
comp1/img_3243r43r
comp1/img_o43nfjr
comp1/img_wjfno43
comp1/img_nrejfner
comp1/img_jrenckerjv
comp1/img_23434k
comp1/img_rkfnk4n
any help would be appreciated.
thanks
You can do this:
>>> data = '/*jsonp*/jsonresp({"img_set":"comp1/img_23434;comp1/img_3243r43r,comp1/img_o43nfjr;comp1/img_wjfno43,comp1/img_nrejfner;comp1/img_jrenckerjv,comp1/img_23434k;comp1/img_rkfnk4n"},"fknreff\",");'
>>> import re
>>> re.findall(r'comp1/img_[^;,"]+', data)
['comp1/img_23434', 'comp1/img_3243r43r', 'comp1/img_o43nfjr', 'comp1/img_wjfno43', 'comp1/img_nrejfner', 'comp1/img_jrenckerjv', 'comp1/img_23434k', 'comp1/img_rkfnk4n']
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
How can I build a nested dictionary from reading configure files in Python, such that I can access it like this:
multi_dict["name1"]["name2"]["name3"] = some_value
My current approach is:
if name1 not in dict:
dict["name1"] = {}
dict["name1"]["name2"] = {}
(etc.)
But this ways seems so boring! Is there a more elegant way to do this?
The configure files that I'm reading are like the following:
[a1]
key1=value1
[a2]
[.a3]
key2=value2
[..a4]
key3=value3
The . prefixes mean "another level of nesting". So in this example, I would set:
dict[a1][key1]=value1
dict[a2][a3][key2]=value2
dict[a2][a3][a4][key3]=value3
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have a text file where I wrote a list of symbolic equations. I need to set the value of a variable with this list.
In other words I'm looking for a command that automatically "copy" all I have written in the text file and "paste" it into an expression such this:
a = all_it's_written_in_the_text_file
Is this possible?
with open(filename, "rt") as f:
a = eval(f.read())
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I need to write a regex, that will traverse through my file and replace each :
href='#!/api/API.
with
href='http://www.domain.com/API. . I currently have this kind of code, that will be run from console :
def replace(file, pattern, substring):
my_file = open(file)
for line in my_file:
my_file.write(line.replace(pattern, substring))
Will sending the given strings work in this case ?
So you want to replace #!/api with http://www.domain.com?
You can just do:
line.replace('#!/api','http://www.domain.com')
No need for regex.