[Solved] x.split has no effect

It’s a dictonary, not a list of strings. I think this is what you’re looking for: data = str({“state”:1,”endTime”:1518852709307,”fileSize”:000000}) #add a str() here data = data.strip(‘{}’) data = data.split(‘,’) for x in data: x=x.split(‘:’)[-1] # set x to x.split(…) print(x) The script below prints out: 1 1518852709307 0 Here is a one-liner version: print (list(map(lambda … Read more

[Solved] Is there a faster solution to solve this kind of job? [closed]

I’m not sure I understand your “job description”, but I think you want this: def find_matches(tuple_of_dicts, key_to_find): return [d for d in tuple_of_dicts if key_to_find in d] So: >>> tuple_of_dicts = ({18: None}, {10: None}, {16: None, 18: None, 5: None, 6: None, 7: None, 10: None}, {16: None}, {7: None}, {10: None}, {18: None}, … Read more

[Solved] pymongo result to String

Gives this: {u’_id’: ObjectId(‘5238273074f8edc6a20c48fe’), u’Command’: u’ABCDEF’, u’processed’: False} But really, all I want is ABCDEF in a string. What you get is a dictionary, you simply need to fetch what you want from it print myDict[ u’Command’] 0 solved pymongo result to String

[Solved] What does “Supports python 3” mean? [closed]

Supporting Python 3 means supporting Python 3 up to the current point release. Python point releases are backward compatible. What works on 3.0 should generally work on 3.4. See PEP 387 for the general guidelines on this policy. Python 3.4 added some deprecations but none of these will affect packages that were once only written … Read more

[Solved] How to call functions in python

Besides from that your function definition for SearchForCapitals has a typo, by which I mean that the line def SerachForCapitals(): should be def SearchForCapitals(): (note the spelling of Search), your code works perfectly fine for me. If this does not fix your problem, you should provide the output you get when running the code. 1 … Read more

[Solved] How to solve this without using zip

How do you do it with zip? I don’t think it get much easier than {chr(96+i):i for i in range(1,27)} Same idea, different indizes, no magic number: {chr(ord(‘a’)+i):i+1 for i in range(26)} 3 solved How to solve this without using zip

[Solved] Invalid Syntax Error Script [closed]

This isn’t Python. This is actually C++ code. You didn’t post the error, so I have to assume that you tried to execute this code as Python, which would obviously be your problem. If you called it Python by mistake, and actually got a C++ error, please post the error. 2 solved Invalid Syntax Error … Read more

[Solved] Printing a smile face :)

how about this def display(x): for i in x: for j in i: j = chr(j) print (j, end = ‘ ‘) print() if each i represent a line, you need add a extra print to start over in the next line 1 solved Printing a smile face 🙂

[Solved] What does asterix * means in Python

The operators in Python are magic. They invoke special methods depending on the class of the operand. In this case a special method called __mul__ is called from the list class, since a list object is on the left-side. In the case of a list, the list is repeated by the number of times given … Read more

[Solved] Can somenone translate this from Ruby to Python. Its a basic map function [closed]

So to answer your questions regarding operators like << or ||= []: << appends an element to an array (or appends strings), in the case above it’s used to append the comment object to either the results array or or the threaded thingy. ||= basically means, if left-hand-side is undefined then evaluate & assign right-hand-side … Read more

[Solved] How to find value of this series using python?

This is the Taylor’s series development of exp(-x). Recognizing this gives you a good opportunity to check your result against math.exp(-x). Simple syntax improvements You don’t need an ‘else’ after the while. Just add the code to be run after the loop at the same indentation level as before the while loop. Mathematical problems Most … Read more

[Solved] Both are almost same codes for House Robber III in leetcode but one is time limit exceed code whereas other is perfect solution to the question [closed]

The first version of dfs calls itself recursively twice, saving the results and reusing them. Here are the two recursive calls: leftpair=dfs(root.left) rightpair=dfs(root.right) The second version of dfs calls itself recursively four times. Here are the four recursive calls, embedded in expressions: left=root.val+dfs(root.left)[1]+dfs(root.right)[1] right=max(dfs(root.left))+max(dfs(root.right)) As you can see, rather than reusing the results of the … Read more