Tagged Questions
0
votes
2answers
17 views
Python function always returns false when comparing to ints
from pip.backwardcompat import raw_input
from PFD import *
def getInput():
try:
n = raw_input("Please enter the file size: ")
int(n)
print(str(n))
order = ...
0
votes
0answers
12 views
import in python on IntelliJ
I'm using IntelliJ platform to use python.
When trying to use the import line such as "import bla" I get an error "No module named.." although I do have this file in my projsct and also have init.py ...
0
votes
1answer
37 views
Replacing words in a string- but with two different words: Python3
Trying to get it so that it takes input the same number of times the certain word appears in the original string and replaces it with each word that was the input.
def replace_parts_of_speech ...
4
votes
1answer
49 views
Determine whether super().__new__ will be object.__new__ in Python 3?
Let's say I have some class that calls __new__, how do I play well with the mro and call up to super classes' __new__ (with arguments) as necessary, but not call object.__new__ with additional ...
0
votes
5answers
49 views
convert list of lists into a string
I have a list, in which is another list and I want to doc.write(a)
a = [[1, 2, "hello"],
[3, 5, "hi There"],
[5,7,"I don't know"]]
doc.write(''.join(a))
TypeError: sequence item 0: ...
3
votes
4answers
41 views
Trying to find a match in two strings - Python
I have a user inputting two strings and then I want to check if there are any similar characters and if there is, get the position where the first similarity occurs, without using the find or index ...
1
vote
0answers
18 views
Python3: StringIO and Elementree encoding
With migration to Python 3 xml.etree.ElementTree's write() doesn't work as expected.
I need to make the following code work with Python3:
tree = ET.ElementTree(root)
fileobj = StringIO()
...
1
vote
2answers
107 views
homework: never ending loop 5**200000
I had an homework assignment: to find the maximal sum of 50,000 consecutive digits in the number 5**200,000.
I know that if i make a for loop over this number it will not end in a feasible time.
I ...
16
votes
4answers
259 views
Does Python have a cleaner way to express if x contains a|b|c|d…?
The Pythonic way to check if a string x is a substring of y is
if x in y:
Finding if x is equivalent to a,b,c,d,e,f, or g is also Pythonic
if x in [a,b,c,d,e,f,g]:
But checking if some string x ...
0
votes
1answer
42 views
python list tree indexing
I have this list where I want to store a name, and inside the name more itemlists with a name and amount, well you can see the rough outline below.
varx = [
{"Name1":
{
...
0
votes
1answer
19 views
Find a function that finds the difference between adjacent values in a list then test against a threshold
So basically I need a function that calculates the difference between each value in a list then tests against the threshold. If the difference between two adjacent numbers are greater than the given ...
2
votes
2answers
27 views
pandas dataframe to dictionary value
I have three column datagram intended to convert in dictionary in the format given:
datagram:
user_id item_id ratings
3 2 3
3 3 4
1 3 1
2 1 4
...
0
votes
1answer
17 views
Unable to log in with a page, using credentials
Below is the code i am using to log into a page and scrape the data from it.
import BeautifulSoup, urllib2
import mechanize
br1=mechanize.Browser()
br1.open('http://coned.com')
...
0
votes
0answers
14 views
wxpython image mouse area selection
I have create the follow image viewer in wxpython, and first i choose an image to open, then i want with mouse to select an area then i want to crop this area and save it, i know how to crop it and ...
0
votes
2answers
28 views
python 3x how to sum float numbers in lines? [on hold]
11 3.81 0.04 0.91 0.40 3.97 2.97 2.05 0.18 1.83 0.80 2.11
2 0.87 0.90
These are two lines in a file, how can I sum all the float numbers? So for the result the ...