title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags list |
|---|---|---|---|---|---|---|---|---|---|
Web scrapping table with hidden part using python | 40,119,941 | <p>I´m trying to get the information from this table:</p>
<pre><code><table class="table4 table4-1 table4-1-1"><thead><tr><th class="estilo1">No</th><th class="estilo2">Si</th><!-- <th><div class="contenedor-v... | 1 | 2016-10-18T23:59:07Z | 40,119,988 | <p>It is actually quite easy to solve. <code>html.parser</code> does not parse this kind of non-well-formed HTML well. Use a <em>more lenient</em> <code>html5lib</code> instead. This works for me:</p>
<pre><code>import requests
from bs4 import BeautifulSoup
response = requests.get('http://www.congresovisible.org/vota... | 1 | 2016-10-19T00:04:23Z | [
"python",
"web-scraping",
"beautifulsoup",
"html-table"
] |
UnicodeEncodeError: 'ascii' codec can't encode characters in position 26-27: ordinal not in range(128) | 40,120,027 | <p>I'm running a job that runs a python script collecting Facebook events data from Facebook Graph API and printing out information about the events using Heroku Scheduler. Since it is an automated job that runs daily at a specific time in the cloud, the printing to screen will be logged into Heroku logs when that job ... | 0 | 2016-10-19T00:10:07Z | 40,120,162 | <p>I don't know about the influences of the different environments. But I was able to solve a similar problem by explicity unicode-encoding the data I wanted to print out (or write to a file, for that matter). Try</p>
<pre><code>print(source['name'].encode('utf-8'))
</code></pre>
<p>or have a look here, for a more co... | 2 | 2016-10-19T00:28:58Z | [
"python",
"facebook",
"heroku",
"encoding"
] |
Command function for button "resets" | 40,120,031 | <p>So in my tkinter python program I am calling on a command when a button is clicked. When that happens it runs a function but in the function I have it set a label to something on the first time the button is clicked and after that it should only update the said label. Basically after the attempt it changes the attem... | 0 | 2016-10-19T00:11:06Z | 40,120,192 | <p>At beginning of function <code>fight</code> you set <code>attempt = 0</code> so you reset it. </p>
<p>Besides <code>attempt</code> is local variable. It is created when you execute function <code>fight</code> and it is deleted when you leave function <code>fight</code>. You have to use global variable (or global <c... | 1 | 2016-10-19T00:33:13Z | [
"python",
"tkinter"
] |
Python How can i read text file like dictionary | 40,120,085 | <p>I hava a text file like this :</p>
<pre><code>"imei": "123456789",
"sim_no": "+90 xxx xxx xx xx",
"device_type": "standart",
"hw_version": "1.01",
"sw_version": "1.02"
</code></pre>
<p>and i want read this file like dictionary. I mean, when i write imei it should give me 123456789. I'm creating free dictionary and... | 0 | 2016-10-19T00:19:20Z | 40,120,113 | <p>I think you can check this <a href="http://stackoverflow.com/questions/4803999/python-file-to-dictionary">post</a>, and you can change the splitting word to ":"
.</p>
<p>Hopefully it helps!</p>
| -1 | 2016-10-19T00:24:15Z | [
"python",
"python-3.x"
] |
Python How can i read text file like dictionary | 40,120,085 | <p>I hava a text file like this :</p>
<pre><code>"imei": "123456789",
"sim_no": "+90 xxx xxx xx xx",
"device_type": "standart",
"hw_version": "1.01",
"sw_version": "1.02"
</code></pre>
<p>and i want read this file like dictionary. I mean, when i write imei it should give me 123456789. I'm creating free dictionary and... | 0 | 2016-10-19T00:19:20Z | 40,121,329 | <p>I tried to come up with a more elegant solution that doesn't use regular expressions, but everything I came up with is far more verbose, so try this:</p>
<pre><code>import re
d = {}
with open('test.txt') as f:
for line in f:
k, v = re.findall(r'"(.+?)"', line)
d[k] = v
print(d)
</code></pre>
... | 1 | 2016-10-19T02:56:03Z | [
"python",
"python-3.x"
] |
Python How can i read text file like dictionary | 40,120,085 | <p>I hava a text file like this :</p>
<pre><code>"imei": "123456789",
"sim_no": "+90 xxx xxx xx xx",
"device_type": "standart",
"hw_version": "1.01",
"sw_version": "1.02"
</code></pre>
<p>and i want read this file like dictionary. I mean, when i write imei it should give me 123456789. I'm creating free dictionary and... | 0 | 2016-10-19T00:19:20Z | 40,121,626 | <p>Use the <code>json</code> module; you've already got legal JSON aside from missing the outer curly braces:</p>
<pre><code>import json
with open("test.txt") as f:
mydict = json.loads('{{ {} }}'.format(f.read()))
</code></pre>
| 2 | 2016-10-19T03:29:17Z | [
"python",
"python-3.x"
] |
Remove the square brackets? (Newbie) | 40,120,103 | <p>I am new to Python and I have somehow ended up with two lists of lists, each of which contains a single integer (float in y below), as follows:</p>
<pre><code>>x
array([[11], [101], [1001], [10001], [100001]], dtype=object)
>y
array([[0.0], [0.0009751319885253906], [0.03459000587463379],
[3.79702901840209... | 0 | 2016-10-19T00:22:26Z | 40,120,271 | <p>If you want a single list, you can use this:</p>
<pre><code>x = [[11], [101], [1001], [10001], [100001]]
newList = [item for list2 in x for item in list2]
</code></pre>
<p>Assume <code>list2</code> are the lists inside <code>x</code>.</p>
<p>So:</p>
<pre><code>newList = [11, 101, 1001, 10001, 100001]
</code></pr... | 0 | 2016-10-19T00:43:06Z | [
"python",
"arrays",
"plot",
"data-fitting"
] |
Remove the square brackets? (Newbie) | 40,120,103 | <p>I am new to Python and I have somehow ended up with two lists of lists, each of which contains a single integer (float in y below), as follows:</p>
<pre><code>>x
array([[11], [101], [1001], [10001], [100001]], dtype=object)
>y
array([[0.0], [0.0009751319885253906], [0.03459000587463379],
[3.79702901840209... | 0 | 2016-10-19T00:22:26Z | 40,120,405 | <p>Without getting into the code behind reading from a file, you'll first want to setup your program with a list of tuples.</p>
<pre><code>#Example empty list
points = []
#x,y = (1, 2) assigns 1 to x and 2 to y
x,y = (1, 2)
#this appends the tuple (x, y) into the points list
points.append((x, y))
</code></pre>
<p>I... | 1 | 2016-10-19T00:59:20Z | [
"python",
"arrays",
"plot",
"data-fitting"
] |
How to skip to a line via character seeking in Python | 40,120,122 | <p>If I have a text file that has a bunch of random text before I get to the stuff I actually want, how do I move the file pointer there? </p>
<p>Say for example my text file looks like this:</p>
<pre><code>#foeijfoijeoijoijfoiej ijfoiejoi jfeoijfoifj i jfoei joi jo ijf eoij oie jojf
#feoijfoiejf ioj oij oi ... | 0 | 2016-10-19T00:25:13Z | 40,120,531 | <p>Try using the <a href="https://docs.python.org/3/library/io.html#io.IOBase.readlines" rel="nofollow">readlines</a> function. This will return a list containing each line. You can use a <code>for</code> loop to parse through each line, searching for what you need, then obtain the number of the line via its index in t... | 0 | 2016-10-19T01:16:36Z | [
"python",
"loops",
"text"
] |
How to skip to a line via character seeking in Python | 40,120,122 | <p>If I have a text file that has a bunch of random text before I get to the stuff I actually want, how do I move the file pointer there? </p>
<p>Say for example my text file looks like this:</p>
<pre><code>#foeijfoijeoijoijfoiej ijfoiejoi jfeoijfoifj i jfoei joi jo ijf eoij oie jojf
#feoijfoiejf ioj oij oi ... | 0 | 2016-10-19T00:25:13Z | 40,120,773 | <p>You can't seek to it directly without knowing the size of the junk data or scanning through the junk data. But it's not too hard to wrap the file in <a href="https://docs.python.org/3/library/itertools.html#itertools.dropwhile" rel="nofollow"><code>itertools.dropwhile</code></a> to discard lines until you see the "g... | 0 | 2016-10-19T01:50:47Z | [
"python",
"loops",
"text"
] |
Python Eve - How to filter by datetime value | 40,120,147 | <p>How can I return items filtered by date or date interval?
I was trying something like this based on the filtering example from eve's <a href="http://python-eve.org/features.html#filtering" rel="nofollow">documentation</a>:</p>
<pre><code>/records/?where={"date": {"$gte": "2016-10-17"}}
</code></pre>
<p>I was thin... | 1 | 2016-10-19T00:27:24Z | 40,124,222 | <p>Try this:</p>
<pre><code>/records?where={"date": {"$gt": "Mon, 17 Oct 2016 03:00:00 GMT"}}
</code></pre>
<p>It uses the <code>DATE_FORMAT</code> setting which defaults to RFC1123.</p>
| 1 | 2016-10-19T06:54:36Z | [
"python",
"mongodb",
"eve"
] |
Find function in Python 3.x | 40,120,151 | <p>When we have the following: </p>
<pre><code>tweet2 = 'Want cheap snacks? Visit @cssu office in BA2283'
</code></pre>
<p><code>print(tweet2[tweet2.find('cheap')])</code> results in the output <code>'c'</code> and I cant wrap my head around how it does this. I tried the visualizer and it didn't show anything. Could ... | 0 | 2016-10-19T00:27:37Z | 40,120,197 | <p><code>tweet2.find('cheap')</code> returns the index at which the beginning of "cheap" is found, and when that index is used in <code>tweet2[index]</code>, it returns the character at that index, which is "c"</p>
| 2 | 2016-10-19T00:34:14Z | [
"python",
"python-3.x"
] |
Find function in Python 3.x | 40,120,151 | <p>When we have the following: </p>
<pre><code>tweet2 = 'Want cheap snacks? Visit @cssu office in BA2283'
</code></pre>
<p><code>print(tweet2[tweet2.find('cheap')])</code> results in the output <code>'c'</code> and I cant wrap my head around how it does this. I tried the visualizer and it didn't show anything. Could ... | 0 | 2016-10-19T00:27:37Z | 40,120,201 | <p>You should consider reading python documentation on string methods and lists </p>
<pre><code># define string variable tweet2
tweet2 = 'Want cheap snacks? Visit @cssu office in BA2283'
# find position of substring 'cheap', which is 5 (strings has 0-based indices in python
n = tweet2.find('cheap')
# print 5th elemen... | 0 | 2016-10-19T00:34:31Z | [
"python",
"python-3.x"
] |
Find function in Python 3.x | 40,120,151 | <p>When we have the following: </p>
<pre><code>tweet2 = 'Want cheap snacks? Visit @cssu office in BA2283'
</code></pre>
<p><code>print(tweet2[tweet2.find('cheap')])</code> results in the output <code>'c'</code> and I cant wrap my head around how it does this. I tried the visualizer and it didn't show anything. Could ... | 0 | 2016-10-19T00:27:37Z | 40,120,204 | <p><code>find</code> returns an index, not a slice.</p>
<p>If you want the full string you can get it like so:</p>
<pre><code>to_find = 'cheap'
ind = tweet2.find(to_find)
print(tweet2[ind:ind+len(to_find)])
</code></pre>
| 0 | 2016-10-19T00:35:09Z | [
"python",
"python-3.x"
] |
Find function in Python 3.x | 40,120,151 | <p>When we have the following: </p>
<pre><code>tweet2 = 'Want cheap snacks? Visit @cssu office in BA2283'
</code></pre>
<p><code>print(tweet2[tweet2.find('cheap')])</code> results in the output <code>'c'</code> and I cant wrap my head around how it does this. I tried the visualizer and it didn't show anything. Could ... | 0 | 2016-10-19T00:27:37Z | 40,120,217 | <p>It's because the find(str, string) method determines if str occurs in string, or in a substring of string and returns the position of first occurrence. So when you call <code>tweet2.find('cheap')</code> it will return the <strong>position</strong> that is the first occurs of cheap.</p>
| 0 | 2016-10-19T00:36:33Z | [
"python",
"python-3.x"
] |
Python runs the commented-out code | 40,120,210 | <p>I have a problem that sometimes <code>docker-py</code> returns an error:</p>
<pre><code>Permission denied.
</code></pre>
<p>I'm trying to fix it. I commented out the piece of code, and received the following picture.</p>
<pre><code>File "/opt/dst/src/utils/runner.py", line 48, in run_code
\#if len(cli.containers... | -2 | 2016-10-19T00:36:05Z | 40,142,703 | <p>Due to an error in the script, worked two instance celery and this error occurred during the operation instance, who has worked with the old code.</p>
| 0 | 2016-10-19T22:44:31Z | [
"python",
"django",
"docker",
"celery"
] |
Efficient way to select most recent index with finite value in column from Pandas DataFrame? | 40,120,299 | <p>I'm trying to find the most recent index with a value that is not 'NaN' relative to the current index. So, say I have a DataFrame with 'NaN' values like this:</p>
<pre><code> A B C
0 2.1 5.3 4.7
1 5.1 4.6 NaN
2 5.0 NaN NaN
3 7.4 NaN NaN
4 3.5 NaN ... | 4 | 2016-10-19T00:46:19Z | 40,120,457 | <p>You may try something like this, convert the <code>index</code> to a series that have the same <code>NaN</code> values as column <code>B</code> and then use <code>ffill()</code> which carries the last non missing index forward for all subsequent <code>NaN</code>s:</p>
<pre><code>import pandas as pd
import numpy as ... | 5 | 2016-10-19T01:06:28Z | [
"python",
"pandas",
"numpy",
"dataframe"
] |
Efficient way to select most recent index with finite value in column from Pandas DataFrame? | 40,120,299 | <p>I'm trying to find the most recent index with a value that is not 'NaN' relative to the current index. So, say I have a DataFrame with 'NaN' values like this:</p>
<pre><code> A B C
0 2.1 5.3 4.7
1 5.1 4.6 NaN
2 5.0 NaN NaN
3 7.4 NaN NaN
4 3.5 NaN ... | 4 | 2016-10-19T00:46:19Z | 40,121,467 | <p>some useful methods to know</p>
<p><strong><em><code>last_valid_index</code></em></strong><br>
<strong><em><code>first_valid_index</code></em></strong><br>
for columns <code>B</code> as of index <code>4</code></p>
<pre><code>df.B.ix[:4].last_valid_index()
1
</code></pre>
<p>you can use this for all columns in th... | 4 | 2016-10-19T03:09:42Z | [
"python",
"pandas",
"numpy",
"dataframe"
] |
Python Argparse: how to make an argument required if and only if one flag is given? | 40,120,379 | <p>I am wondering how can I make one argument required when one flag is given, and optional when that flag is not given?</p>
<pre><code>import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-c', '--convert', action = 'store_true')
parser.add_argument('-l', '--lookup', action = 'store_true')
parser... | 0 | 2016-10-19T00:55:49Z | 40,120,570 | <p>This isn't something <code>argparse</code> can enforce on its own. What you can do is define <code>name</code> to be optional, then check after parsing if your constraint is met.</p>
<pre><code>import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-c', '--convert', action='store_true')
parser.a... | 2 | 2016-10-19T01:22:53Z | [
"python",
"python-3.x",
"arguments",
"argparse"
] |
Python Argparse: how to make an argument required if and only if one flag is given? | 40,120,379 | <p>I am wondering how can I make one argument required when one flag is given, and optional when that flag is not given?</p>
<pre><code>import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-c', '--convert', action = 'store_true')
parser.add_argument('-l', '--lookup', action = 'store_true')
parser... | 0 | 2016-10-19T00:55:49Z | 40,120,611 | <p>There isn't anything in <code>argparse</code> to do this directly; but it can be approximated in various ways</p>
<pre><code>parser.add_argument('-c', '--convert', action = 'store_true')
parser.add_argument('-l', '--lookup', action = 'store_true')
parser.add_argument('name', nargs='?', default='good default')
</co... | 1 | 2016-10-19T01:28:48Z | [
"python",
"python-3.x",
"arguments",
"argparse"
] |
error in code involving while loop and removing items from string | 40,120,390 | <p>I have a code that downloads tweets and I am trying to sort through it labeling it as positive or negative each time i label a tweet I want to remove it from the string so I won't be asked to label it again here is my code so far</p>
<pre><code>while True:
if len(tweet_list) == 0:
break
else:
... | 0 | 2016-10-19T00:57:09Z | 40,120,511 | <p>You could do something like:</p>
<pre><code>newList = []
for myLetter in myList:
if myLetter is not 'x':
newList.append(myLetter)
newString = ''.join(newList)
</code></pre>
| 0 | 2016-10-19T01:13:54Z | [
"python",
"string",
"while-loop",
"tweepy"
] |
error in code involving while loop and removing items from string | 40,120,390 | <p>I have a code that downloads tweets and I am trying to sort through it labeling it as positive or negative each time i label a tweet I want to remove it from the string so I won't be asked to label it again here is my code so far</p>
<pre><code>while True:
if len(tweet_list) == 0:
break
else:
... | 0 | 2016-10-19T00:57:09Z | 40,120,881 | <p>Make an empty list outside out of your while loop like this:</p>
<pre><code>tweet_pos = []
tweet_neg = []
alreadySeen = []
</code></pre>
<p>Revise your first <code>if</code> statement in your code like so:</p>
<pre><code>if len(alreadySeen) == 20:
break
</code></pre>
<p>Make sure when you're displaying t... | 0 | 2016-10-19T02:03:46Z | [
"python",
"string",
"while-loop",
"tweepy"
] |
What am I missing on this spyder Loan Calculator? | 40,120,674 | <p>I´m learning Python at one of my college classes and I was asked to create a "Loan Calculator".... I might have an idea but I´m not sure how to fix an error that I´m getting <code>TypeError: 'float' object is not subscriptable</code></p>
<p>This is the announcement
The user has to enter the cost of the loan, in... | 0 | 2016-10-19T01:36:29Z | 40,120,769 | <p>Needed a few changes: </p>
<pre><code># Loan Calculator
# Equation: M = L[i(1+i)^n]/[(1+i)(n)-1]
print("Loan Calculator")
L = float(input("Loan amount: "))
i = float(input("Interest rate: "))
# Remember: 5% ---> i=0.05
n = float(input("Number of payments: "))
M = L*(i*(1+i)**n)/((1+i)**(n)-1)
# M = Mo... | 0 | 2016-10-19T01:50:23Z | [
"python"
] |
How to Create One Category from 2 Datasets in Python | 40,120,679 | <p>I have two data sets that both have data in it like follows:</p>
<p>Data set 1:</p>
<pre><code>Country Year Cause Gender Deaths
2090 2011 A000 1 70340
2090 2010 A001 2 53449
2090 2009 A002 1 1731
2090 2008 A003 2 1270
2090 2007 A004 1 ... | 0 | 2016-10-19T01:37:06Z | 40,121,212 | <p>So my understanding of your problem is (correct me if I'm wrong), you have two datasets which both have a "Cause" column/variable. But the encoding of this "Cause" column in two datasets are different. </p>
<p>In Dataset1, perhaps the encoding says:</p>
<pre><code>Road Traffic Accidents Category: A001, A003
Heart ... | 0 | 2016-10-19T02:43:20Z | [
"python",
"dataset",
"category",
"jupyter-notebook"
] |
Print user input in "cascade" of characters? | 40,120,698 | <p>I am trying to create code that gathers a user's first and last name (input order is last, first) and prints it first, last in a cascading way:</p>
<pre><code> J
o
h
n
S
m
i
t
h
</code></pre>
<p>I'm really close, but I don't like the way my code works. I t... | 1 | 2016-10-19T01:39:25Z | 40,120,777 | <p>You can write a generic function, like the one shown below and reuse for your strings.</p>
<pre><code>def cascade_name(name):
for i, c in enumerate(name):
print '\t'*(i+1), c
</code></pre>
<p>output:</p>
<pre><code>>>> cascade_name("foo")
f
o
o
</code></pre>
<p>In you... | 1 | 2016-10-19T01:51:05Z | [
"python",
"string",
"printing"
] |
How to write unittest for variable assignment in python? | 40,120,770 | <p>This is in <code>Python 2.7</code>. I have a class called <code>class A</code>, and there are some attributes that I want to throw an exception when being set by the user:</p>
<pre><code>myA = A()
myA.myattribute = 9 # this should throw an error
</code></pre>
<p>I want to write a <code>unittest</code> that ensu... | 3 | 2016-10-19T01:50:34Z | 40,120,790 | <p><code>self.assertRaises</code> takes a callable (and optionally one or more arguments for that callable) as its argument; you are providing the value that results from calling the callable with its arguments. The correct test would be <strike><code>self.assertRaises(AttributeError, eval, 'myA.myattribute = 9')</code... | 1 | 2016-10-19T01:53:29Z | [
"python",
"python-2.7",
"unit-testing",
"python-unittest"
] |
How to write unittest for variable assignment in python? | 40,120,770 | <p>This is in <code>Python 2.7</code>. I have a class called <code>class A</code>, and there are some attributes that I want to throw an exception when being set by the user:</p>
<pre><code>myA = A()
myA.myattribute = 9 # this should throw an error
</code></pre>
<p>I want to write a <code>unittest</code> that ensu... | 3 | 2016-10-19T01:50:34Z | 40,120,791 | <p>You can also use <code>assertRaises</code> as a context manager:</p>
<pre><code>with self.assertRaises(AttributeError):
myA.myattribute = 9
</code></pre>
<p>The <a href="https://docs.python.org/3/library/unittest.html#basic-example" rel="nofollow">documentation shows more examples for this if you are intereste... | 4 | 2016-10-19T01:53:41Z | [
"python",
"python-2.7",
"unit-testing",
"python-unittest"
] |
how to hide axes in matplotlib.pyplot | 40,120,818 | <p>I put the image in a <code>numpy</code> array, and draw it with the following code. How can I tell the program not to draw the axes, like <code>(0, 100, 200...)</code> </p>
<pre><code>import matplotlib.pyplot as plt
plt.figure()
plt.imshow(output_ndarray)
plt.savefig(output_png)
</code></pre>
<p><a href="https:... | 1 | 2016-10-19T01:56:44Z | 40,121,071 | <pre><code>plt.xticks([])
plt.yticks([])
</code></pre>
<p><a href="http://matplotlib.org/api/pyplot_api.html" rel="nofollow">http://matplotlib.org/api/pyplot_api.html</a></p>
| 2 | 2016-10-19T02:26:38Z | [
"python",
"numpy",
"matplotlib"
] |
how to hide axes in matplotlib.pyplot | 40,120,818 | <p>I put the image in a <code>numpy</code> array, and draw it with the following code. How can I tell the program not to draw the axes, like <code>(0, 100, 200...)</code> </p>
<pre><code>import matplotlib.pyplot as plt
plt.figure()
plt.imshow(output_ndarray)
plt.savefig(output_png)
</code></pre>
<p><a href="https:... | 1 | 2016-10-19T01:56:44Z | 40,121,409 | <p><a href="https://i.stack.imgur.com/M9NXQ.png" rel="nofollow"><img src="https://i.stack.imgur.com/M9NXQ.png" alt="enter image description here"></a>You can also use...</p>
<pre><code>plt.axis('off')
</code></pre>
<p><a href="https://i.stack.imgur.com/STpTP.png" rel="nofollow"><img src="https://i.stack.imgur.com/STp... | 2 | 2016-10-19T03:03:28Z | [
"python",
"numpy",
"matplotlib"
] |
Error importing storage module.whitenoise.django | 40,121,126 | <p>I'm trying to deploy a basic Django app to Heroku, but am getting an error when I try to deploy.</p>
<p>It looks like the error is with <em>whitenoise</em>. I have <em>six</em> installed as part of my requirements so it should handle urllib.parse.</p>
<p>Here is the error:</p>
<pre><code>remote: File "/a... | 0 | 2016-10-19T02:33:06Z | 40,127,263 | <p>You're using an unsupported version of Django. Django 1.5 has been out of mainstream support for three years, and out of extended support for two.
See here: <a href="https://www.djangoproject.com/download/#supported-versions" rel="nofollow">https://www.djangoproject.com/download/#supported-versions</a></p>
<p>The l... | 0 | 2016-10-19T09:23:24Z | [
"python",
"django",
"heroku"
] |
python can not get my all examples right | 40,121,169 | <p>For my own understanding, I write 2 functions and use my examples to test. Similarly, both 2 functions have 1 example right and one wrong.
1.
def count_from_word_list(tweet, L):
"""(str, list of str) -> int </p>
<p>The first parameter represents a tweet. The second parameter is a list of words. Count how many t... | -3 | 2016-10-19T02:39:08Z | 40,121,648 | <h2>First function</h2>
<p>I assume from your example that the body of your first function looks like</p>
<pre><code>def count_from_word_list(tweet, L):
count = 0
for i in L:
if i in tweet:
count = count + 1
return count
</code></pre>
<p>Lets think about what is happening in logical s... | 0 | 2016-10-19T03:31:33Z | [
"python"
] |
Using python request library to dynamically get HTTP Error String | 40,121,187 | <p>I've been asked to swap over from urllib2 to the requests library because the library is simpler to use and doesn't cause exceptions.</p>
<p>I can get the HTTP error code with response.status_code but I don't see a way to get the error message for that code. Normally, I wouldn't care, but I'm testing an API and the... | 0 | 2016-10-19T02:40:25Z | 40,121,270 | <pre><code>response = requests.get(url)
error_message = response.reason
</code></pre>
| 1 | 2016-10-19T02:49:43Z | [
"python",
"httprequest",
"urllib2"
] |
Using python request library to dynamically get HTTP Error String | 40,121,187 | <p>I've been asked to swap over from urllib2 to the requests library because the library is simpler to use and doesn't cause exceptions.</p>
<p>I can get the HTTP error code with response.status_code but I don't see a way to get the error message for that code. Normally, I wouldn't care, but I'm testing an API and the... | 0 | 2016-10-19T02:40:25Z | 40,121,278 | <p>In <a href="https://docs.python.org/3.4/library/http.client.html#httpresponse-objects" rel="nofollow">HTTPResponse there's a <code>reason</code> attribute</a> that returns the reason phrase from the response's status line. In <a href="http://docs.python-requests.org/en/master/api/#requests.Response" rel="nofollow">t... | 0 | 2016-10-19T02:50:57Z | [
"python",
"httprequest",
"urllib2"
] |
using a Python script w 2nd Order Runge Kutta method to solve the equation of a pendulum, how do I add a calculation of the KE, PE, and TE? | 40,121,203 | <p>I am unable to figure out how to program my script to plot KE, PE, and TE. I have included multiple ########### in the parts of my code where I feel the problem lies. </p>
<pre><code>def pendulum_runge_kutta(theta0,omega0,g,tfinal,dt):
# initialize arrays
t = np.arange(0.,tfinal+dt,dt) # time ... | 0 | 2016-10-19T02:42:09Z | 40,137,946 | <p>You are missing a factor 1/2 in both theta updates. The formulas for the midpoint method apply uniformly to all components of the first order system.</p>
<p>The potential energy should contain the integral of <code>sin(x)</code>, <code>C-cos(x)</code>. For instance, </p>
<pre><code>Pe[i+1] = m*g*L*(1-np.cos(theta[... | 0 | 2016-10-19T17:30:35Z | [
"python",
"physics",
"runge-kutta"
] |
Initiate new processes instead of reusing prior in Python | 40,121,205 | <p>I am using multiprocessing in Python with:</p>
<pre><code>import multiprocessing as mp
all_arguments = range(0,20)
pool = mp.Pool(processes=7)
all_items = [pool.apply_async(main_multiprocessing_function, args=(argument_value,)) for argument_value in all_arguments]
for item in all_items:
item.get()
</code></pr... | 0 | 2016-10-19T02:42:46Z | 40,121,643 | <p>From the <a href="https://docs.python.org/3.6/library/multiprocessing.html#multiprocessing.pool.Pool" rel="nofollow">docs</a>:</p>
<blockquote>
<p>maxtasksperchild is the number of tasks a worker process can complete
before it will exit and be replaced with a fresh worker process, to
enable unused resources t... | 2 | 2016-10-19T03:30:46Z | [
"python",
"python-multiprocessing"
] |
Python string to dictionary with json (not working) | 40,121,231 | <p>I have a text file like this :</p>
<p>"imei": "123456789",
"sim_no": "+90 xxx xxx xx xx",
"device_type": "standart",
"hw_version": "1.01",
"sw_version": "1.02"</p>
<p>and i want to convert to dictionary this file. Because i want to take values. </p>
<pre><code>import json
from time import sleep
def buffer(data):... | 0 | 2016-10-19T02:45:08Z | 40,121,388 | <pre><code>import json
from time import sleep
def buffer(data):
s = json.loads(data)
dicto = {}
tmp_list = s.split(',')
for e in tmp_list:
tmp = e.split(':')
dicto[tmp[0]] = tmp[1]
print(type(dicto))
file=open("config.txt", "r").read()
jsondata=json.dumps(file)
buffer(jso... | -1 | 2016-10-19T03:01:22Z | [
"python",
"json",
"python-3.x"
] |
Python string to dictionary with json (not working) | 40,121,231 | <p>I have a text file like this :</p>
<p>"imei": "123456789",
"sim_no": "+90 xxx xxx xx xx",
"device_type": "standart",
"hw_version": "1.01",
"sw_version": "1.02"</p>
<p>and i want to convert to dictionary this file. Because i want to take values. </p>
<pre><code>import json
from time import sleep
def buffer(data):... | 0 | 2016-10-19T02:45:08Z | 40,121,587 | <p>Seems like you could just add the outer curly braces JSON requires:</p>
<pre><code>with open('config.txt', 'r+') as f:
newdata = '{{ {} }}'.format(f.read())
f.seek(0)
f.write(newdata)
</code></pre>
<p>Otherwise, the file is already JSON, so no actual use of the <code>json</code> module is required (unl... | 2 | 2016-10-19T03:25:29Z | [
"python",
"json",
"python-3.x"
] |
Python string to dictionary with json (not working) | 40,121,231 | <p>I have a text file like this :</p>
<p>"imei": "123456789",
"sim_no": "+90 xxx xxx xx xx",
"device_type": "standart",
"hw_version": "1.01",
"sw_version": "1.02"</p>
<p>and i want to convert to dictionary this file. Because i want to take values. </p>
<pre><code>import json
from time import sleep
def buffer(data):... | 0 | 2016-10-19T02:45:08Z | 40,122,103 | <p>I have to solve this question :</p>
<p>We have a text file like this :</p>
<pre><code>"imei": "123456789",
"sim_no": "+90 xxx xxx xx xx",
"device_type": "standart",
"hw_version": "1.01",
"sw_version": "1.02"
</code></pre>
<p>And we should read this JSON data, then we should read this data each 1 min and put to bu... | 0 | 2016-10-19T04:24:17Z | [
"python",
"json",
"python-3.x"
] |
Python : Web Scraping Specific Keywords | 40,121,232 | <p>My Question shouldn't be too hard to answer, The problem im having is im not sure how to scrape a website for specific keywords.. I'm quite new to Python.. So i know i need to add in some more details , Firstly what i dont want to do is use Beautiful Soup or any of those libs, im using lxml and requests, What i do w... | 0 | 2016-10-19T02:45:14Z | 40,121,436 | <p>You're using <code>lxhtml</code> to build the HTML into an object model, so you probably want to use <code>flashTree.xpath</code> to search the DOM using XML Path Language. Find the path you want in the source DOM and then write an xpath that extracts it, your web browser's developer tools and <a href="http://www.w3... | 1 | 2016-10-19T03:06:45Z | [
"python",
"web",
"web-crawler",
"screen-scraping",
"scrape"
] |
Python : Web Scraping Specific Keywords | 40,121,232 | <p>My Question shouldn't be too hard to answer, The problem im having is im not sure how to scrape a website for specific keywords.. I'm quite new to Python.. So i know i need to add in some more details , Firstly what i dont want to do is use Beautiful Soup or any of those libs, im using lxml and requests, What i do w... | 0 | 2016-10-19T02:45:14Z | 40,121,984 | <p>Here goes my attempt:</p>
<pre><code>import requests [1]
response = requests.get(flashSite) [2]
myPage = response.content [3]
for line in myPage.splitlines(): [4]
if '.swf' in line: [5]
start = line.find('http') [6]
end = line.find('.swf') + 4 [7]
print line[start:end] [8]
</code></pre>
... | 0 | 2016-10-19T04:12:30Z | [
"python",
"web",
"web-crawler",
"screen-scraping",
"scrape"
] |
str.replace function raise erorr that an integer is required | 40,121,350 | <p>I wanna ask the problem I encountered. At first,
Let me show you my whole code</p>
<pre><code>df1 = pd.read_excel(r'E:\ë´ë
¼ë¬¸ìë£\골목ìê¶ ë°ì´í°\ì´íìë¡ 54길 ë´ì©ëºê±°.xlsx' , sheetname='first_day_datas')
df1.registerdate= df1.registerdate.astype(str) # ì¹¼ë¼ ìì± ë°ê¾¸ê¸°
df2 = pd.to_dat... | 4 | 2016-10-19T02:58:12Z | 40,121,556 | <pre><code>df2 = pd.to_datetime(df1['registerdate'].str[0:10])
# \____________/
# returns a series
</code></pre>
<hr>
<pre><code>df2['registerdate'].str.replace('-', '').str.strip()
#\_______________/
# is only something
# if 'registration
# is in the index
# this is probably the source of your error
</code></... | 2 | 2016-10-19T03:21:49Z | [
"python",
"pandas"
] |
str.replace function raise erorr that an integer is required | 40,121,350 | <p>I wanna ask the problem I encountered. At first,
Let me show you my whole code</p>
<pre><code>df1 = pd.read_excel(r'E:\ë´ë
¼ë¬¸ìë£\골목ìê¶ ë°ì´í°\ì´íìë¡ 54길 ë´ì©ëºê±°.xlsx' , sheetname='first_day_datas')
df1.registerdate= df1.registerdate.astype(str) # ì¹¼ë¼ ìì± ë°ê¾¸ê¸°
df2 = pd.to_dat... | 4 | 2016-10-19T02:58:12Z | 40,121,723 | <p>It seems df2 has no column 'registerdate', It is a timestamp list.
I think <code>df2.map(lambda x: x.strftime('%Y%m%d')</code> can convert timestamp to the format you need.</p>
| 0 | 2016-10-19T03:42:02Z | [
"python",
"pandas"
] |
Control chromium kiosk mode url from python | 40,121,382 | <p><a href="http://stackoverflow.com/questions/30123632/using-python-to-start-a-browser-chromium-and-change-the-url">Using Python to start a browser (Chromium) and change the url</a></p>
<p>The linked question is asking exactly what I want but I don't know how to implement the answer that is just to uses Selenium. </p... | 0 | 2016-10-19T03:00:48Z | 40,122,083 | <p>You can add options to selenium's chromedriver, similar to how you would using <code>os.system</code></p>
<pre><code>from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--kiosk")
driver = webdriver.Chrome(chrome_options=chrome_... | 0 | 2016-10-19T04:21:52Z | [
"python",
"raspberry-pi"
] |
Receive ImportError: cannot import name 'DictVectorizer' | 40,121,483 | <p>I have installed scikit-learn to a python environment through Anaconda. This is on Ubuntu 14.04. The line in my code it is complaining about is</p>
<pre><code>from sklearn.feature_extraction.text import DictVectorizer
</code></pre>
<p>The error is </p>
<pre><code>Import Error: cannot import name 'DictVectorizer'... | 0 | 2016-10-19T03:10:59Z | 40,121,775 | <p>I'm unfamiliar with that library. However, looking at the source on github it appears you have the import path wrong.</p>
<p><code>from sklearn.feature_extraction import DictVectorizer</code> should work</p>
| 1 | 2016-10-19T03:49:59Z | [
"python",
"scikit-learn"
] |
Clustered Stacked Bar in Python Pandas | 40,121,562 | <p>I have created a single stacked bar chart but I want to have them clustered. Exactly something like the picture. </p>
<p>Wondering if it's possible. </p>
<p><a href="https://i.stack.imgur.com/SoxmW.png" rel="nofollow">link to picture</a></p>
| -4 | 2016-10-19T03:22:29Z | 40,121,800 | <pre><code>df = pd.DataFrame(dict(Subsidy=[3, 3, 3],
Bonus=[1, 1, 1],
Expense=[2, 2, 2]),
list('ABC'))
df
</code></pre>
<p><a href="https://i.stack.imgur.com/OrFdi.png" rel="nofollow"><img src="https://i.stack.imgur.com/OrFdi.png" alt="enter image descri... | 3 | 2016-10-19T03:51:49Z | [
"python",
"pandas",
"matplotlib"
] |
Efficient matrix multiplication in Matlab | 40,121,582 | <p>I have two matrices, <code>A</code> (N by K) and <code>B</code> (N by M) and I would like to concentrate <code>A</code> and <code>B</code> into a tensor <code>C</code> (N by K by M) where <code>C(n,k,m) = A(n,k) * B(n,m)</code>. I know how to do it in python like </p>
<pre><code>C = B[:,numpy.newaxis,:] * A[:,:,... | 2 | 2016-10-19T03:24:54Z | 40,123,257 | <p>Take advantage of the implicit expansion feature of <a href="https://www.mathworks.com/help/matlab/ref/bsxfun.html" rel="nofollow"><code>bsxfun</code></a>. Use <a href="https://www.mathworks.com/help/matlab/ref/permute.html" rel="nofollow"><code>permute</code></a> to have your <code>B</code> as an Nx1xM matrix:</p>
... | 2 | 2016-10-19T05:53:28Z | [
"python",
"matlab",
"numpy",
"matrix",
"matrix-multiplication"
] |
How to run/interact with a Golang executable in Python? | 40,121,657 | <p>I have a command-line Golang executable on Windows named <code>cnki-downloader.exe</code> (open-sourced here: <a href="https://github.com/amyhaber/cnki-downloader" rel="nofollow">https://github.com/amyhaber/cnki-downloader</a>). I want to run this executable in Python, and interact with it (get its output, then inpu... | -2 | 2016-10-19T03:32:15Z | 40,123,207 | <p>Looking at the <a href="https://docs.python.org/2/library/subprocess.html#popen-objects" rel="nofollow">documentation</a> for the subprocess module you are using, it seems they have a warning about deadlocks using <code>stdout.read()</code> and friends:</p>
<blockquote>
<p>Warning This will deadlock when using st... | 1 | 2016-10-19T05:50:43Z | [
"python",
"windows",
"go",
"command-line"
] |
H2O merging of scores with original data set | 40,121,673 | <p>I'm using H2O to generate predictions on a large data set with user ID as one of the columns. However, once I score the data set the predictions data set does not contain the ID... The only thing that keeps things working is the order of the scores matches the order of the input data set, which is pretty sloppy IMO.... | 1 | 2016-10-19T03:35:24Z | 40,125,551 | <p>Yes, you simply need to cbind the information from the frames that you want as your final output. Here is a full example: I'm doing a regression to predict a patient's height based on their age and risk category. (!)</p>
<pre><code>import h2o
h2o.init()
patients = {
'age':[29, 33, 65],
'height':[188, 157, 175.... | 0 | 2016-10-19T08:05:12Z | [
"python",
"h2o"
] |
how to convert date-time to epoch in python? | 40,121,686 | <p>I want this particular date-time to be converted to epoch but it is giving me format error. what format should i use to do the following so that it can be json rendered. "2016-10-14 14:34:14+00:00". I am using python 2.7 and django 1.10</p>
<pre><code>stra = "instance[0].Timing"
formata = "%Y-%m-%d %H:%M:%S+00:00"
... | 0 | 2016-10-19T03:37:07Z | 40,121,732 | <p>Option 1, you can use <code>isoformat()</code>:</p>
<pre><code>from datetime import datetime
print(datetime.utcnow().isoformat())
# '2016-10-19T03:39:40.485521'
</code></pre>
<p>Option 2, <code>strftime()</code>, do not confuse it with <code>strptime</code>:</p>
<pre><code>print(datetime.utcnow().strftime('%Y-%m... | 0 | 2016-10-19T03:43:24Z | [
"python",
"json",
"django",
"datetime",
"epoch"
] |
how to convert date-time to epoch in python? | 40,121,686 | <p>I want this particular date-time to be converted to epoch but it is giving me format error. what format should i use to do the following so that it can be json rendered. "2016-10-14 14:34:14+00:00". I am using python 2.7 and django 1.10</p>
<pre><code>stra = "instance[0].Timing"
formata = "%Y-%m-%d %H:%M:%S+00:00"
... | 0 | 2016-10-19T03:37:07Z | 40,123,074 | <p>Actually in django datetime object are converted in epoch as following way.</p>
<p><strong>Emample 1</strong></p>
<pre><code>import datetime
current_date = datetime.datetime.now()
epoch = int(current_date.strftime("%s")) * 1000
</code></pre>
<p><strong>Example 2</strong></p>
<pre><code>import datetime
date_obje... | 0 | 2016-10-19T05:43:08Z | [
"python",
"json",
"django",
"datetime",
"epoch"
] |
how to convert date-time to epoch in python? | 40,121,686 | <p>I want this particular date-time to be converted to epoch but it is giving me format error. what format should i use to do the following so that it can be json rendered. "2016-10-14 14:34:14+00:00". I am using python 2.7 and django 1.10</p>
<pre><code>stra = "instance[0].Timing"
formata = "%Y-%m-%d %H:%M:%S+00:00"
... | 0 | 2016-10-19T03:37:07Z | 40,123,710 | <p>This is a literal string, it's not pulling data out of whatever instance you have:</p>
<pre><code>stra = "instance[0].Timing"
</code></pre>
<p>Perhaps you meant the following instead?</p>
<pre><code>stra = instance[0].Timing
</code></pre>
| 0 | 2016-10-19T06:24:19Z | [
"python",
"json",
"django",
"datetime",
"epoch"
] |
Keep identical values in default dict | 40,121,804 | <p>I have the following two lists:</p>
<pre><code>prefix = ['AGG', 'CAG', 'CAG', 'GAG', 'GGA', 'GGG', 'GGG']
suffix = ['GGG', 'AGG', 'AGG', 'AGG', 'GAG', 'GGA', 'GGG']
</code></pre>
<p>I am trying to use defaultdict to get this result:</p>
<pre><code>AGG -> GGG
CAG -> AGG,AGG
GAG -> AGG
GGA -> GAG
GGG -&... | 1 | 2016-10-19T03:52:11Z | 40,121,825 | <p>Use a <code>defaultdict</code> of <code>list</code>, instead of <code>set</code>. Sets removes duplicates. </p>
<p>Your code is already fine, you'll just have to change the </p>
<pre><code>nodes[pre].add(suf)
</code></pre>
<p>to</p>
<pre><code>nodes[pre].append(suf)
</code></pre>
<p>For the printing, it will ... | 2 | 2016-10-19T03:54:43Z | [
"python",
"defaultdict"
] |
Lambda that searches list and increments | 40,121,807 | <p>Using a Python <code>lambda</code> can you check whether an element exists in another list (of maps) and also increment a variable? I'm attempting to optimise/refactor my code using a lambda but I've gone and confused myself.</p>
<p>Below is my existing code that I want to convert to a lambda. Is it possible to do ... | 0 | 2016-10-19T03:52:23Z | 40,121,831 | <p>It is possible to hack around it but <code>lambda</code>s should not mutate, they should return a new result. Also you should not overcomplicate <code>lambda</code>s, they are meant for short quick functions such a <code>key</code> for a <code>sort</code> method</p>
| 1 | 2016-10-19T03:55:24Z | [
"python",
"lambda"
] |
Lambda that searches list and increments | 40,121,807 | <p>Using a Python <code>lambda</code> can you check whether an element exists in another list (of maps) and also increment a variable? I'm attempting to optimise/refactor my code using a lambda but I've gone and confused myself.</p>
<p>Below is my existing code that I want to convert to a lambda. Is it possible to do ... | 0 | 2016-10-19T03:52:23Z | 40,121,895 | <p>You can't use <code>+=</code> (or assignment of any kind) in a <code>lambda</code> at all, and using <code>filter</code> for side-effects is a terrible idea (this pattern looks kind of like how <code>reduce</code> is used, but it's hard to tell what you're trying to do).</p>
<p>It looks like you're trying to count ... | 3 | 2016-10-19T04:01:42Z | [
"python",
"lambda"
] |
Lambda that searches list and increments | 40,121,807 | <p>Using a Python <code>lambda</code> can you check whether an element exists in another list (of maps) and also increment a variable? I'm attempting to optimise/refactor my code using a lambda but I've gone and confused myself.</p>
<p>Below is my existing code that I want to convert to a lambda. Is it possible to do ... | 0 | 2016-10-19T03:52:23Z | 40,121,956 | <p>Probably you should be using a list comprehension. eg</p>
<pre><code>current_order_ids = {order['id'] for order in current_orders}
not_del = [order for order in deleted_orders if order['id'] not in current_order_ids]
for order in not_del:
logger.error("Failed to delete ORDER with ID: %s", order['id'])
</code><... | 1 | 2016-10-19T04:08:20Z | [
"python",
"lambda"
] |
Extracting year from string in python | 40,121,822 | <p>How can I parse the foll. in python to extract the year:</p>
<pre><code>'years since 1250-01-01 0:0:0'
</code></pre>
<p>The answer should be 1250</p>
| -1 | 2016-10-19T03:54:28Z | 40,121,869 | <p>There are all sorts of ways to do it, here are several options:</p>
<ul>
<li><p><a href="https://pypi.python.org/pypi/python-dateutil" rel="nofollow"><code>dateutil</code> parser</a> in a "fuzzy" mode:</p>
<pre><code>In [1]: s = 'years since 1250-01-01 0:0:0'
In [2]: from dateutil.parser import parse
In [3]: par... | 6 | 2016-10-19T03:59:30Z | [
"python",
"regex"
] |
Extracting year from string in python | 40,121,822 | <p>How can I parse the foll. in python to extract the year:</p>
<pre><code>'years since 1250-01-01 0:0:0'
</code></pre>
<p>The answer should be 1250</p>
| -1 | 2016-10-19T03:54:28Z | 40,121,870 | <p>You can use a regex with a capture group around the four digits, while also making sure you have a particular pattern around it. I would probably look for something that:</p>
<ul>
<li><p>4 digits and a capture <code>(\d{4})</code></p></li>
<li><p>hyphen <code>-</code></p></li>
<li><p>two digits <code>\d{2}</code></... | 4 | 2016-10-19T03:59:46Z | [
"python",
"regex"
] |
Extracting year from string in python | 40,121,822 | <p>How can I parse the foll. in python to extract the year:</p>
<pre><code>'years since 1250-01-01 0:0:0'
</code></pre>
<p>The answer should be 1250</p>
| -1 | 2016-10-19T03:54:28Z | 40,121,874 | <p>The following regex should make the four digit year available as the first capture group:</p>
<pre><code>^.*\(d{4})-\d{2}-\d{2}.*$
</code></pre>
| 3 | 2016-10-19T04:00:07Z | [
"python",
"regex"
] |
Compare list of dictionary in Robot Framework | 40,121,844 | <p>I have two list of list of dictionary and i want to compare the vale of first list dictionary to second list of dictionary</p>
<p>For example:</p>
<pre><code>Dictionary A contains [{Name:C}, {Name:A}, {Name:B}]
Dictionary B contains [{Name:A}, {Name:B}, {Name:C}]
</code></pre>
<p>How to take A's 1st Dictionary {N... | 0 | 2016-10-19T03:57:28Z | 40,121,904 | <p>You want to see if some list of dictionaries contains at least one dictionary that maps <code>'name': 'C'</code> ?</p>
<pre><code>any(d['name'] == 'C' for d in list_of_dict if 'name' in dict)
</code></pre>
| 0 | 2016-10-19T04:02:41Z | [
"python",
"list",
"dictionary",
"robotframework"
] |
Compare list of dictionary in Robot Framework | 40,121,844 | <p>I have two list of list of dictionary and i want to compare the vale of first list dictionary to second list of dictionary</p>
<p>For example:</p>
<pre><code>Dictionary A contains [{Name:C}, {Name:A}, {Name:B}]
Dictionary B contains [{Name:A}, {Name:B}, {Name:C}]
</code></pre>
<p>How to take A's 1st Dictionary {N... | 0 | 2016-10-19T03:57:28Z | 40,142,587 | <p>If I understand your question correctly, you should be able to do this using the built in Collections library. This code took the values in one dictionary and checked to see if the value exists in the other. </p>
<pre><code>*** Settings ***
Library Collections
*** Variables ***
&{DICTONARY_ONE} = name1=a na... | 0 | 2016-10-19T22:32:06Z | [
"python",
"list",
"dictionary",
"robotframework"
] |
how can I test for ordered subset | 40,121,871 | <p><strong><em>firstly</em></strong><br>
I need to be able to test that <code>'abc'</code> is an ordered subset of <code>'axbyc'</code> and <code>'egd'</code> is not an ordered subset of <code>'edg'</code>. Another way to say it is that it is an ordered subset if I can remove specific characters of of one string and h... | 3 | 2016-10-19T03:59:56Z | 40,121,920 | <p>For the first part of the question:</p>
<pre><code>def ordered_subset(s1, s2):
s2 = iter(s2)
try:
for c in s1:
while next(s2) != c:
pass
else:
return True
except StopIteration:
return False
</code></pre>
<p>For the second part of the quest... | 2 | 2016-10-19T04:04:18Z | [
"python",
"pandas"
] |
how can I test for ordered subset | 40,121,871 | <p><strong><em>firstly</em></strong><br>
I need to be able to test that <code>'abc'</code> is an ordered subset of <code>'axbyc'</code> and <code>'egd'</code> is not an ordered subset of <code>'edg'</code>. Another way to say it is that it is an ordered subset if I can remove specific characters of of one string and h... | 3 | 2016-10-19T03:59:56Z | 40,122,385 | <p>use <code>'.*'.join</code> to create a regex pattern to match against sequence.</p>
<pre><code>import re
import pandas as pd
s1 = pd.Series(['abc', 'egd'])
s2 = pd.Series(['axbyc', 'edg'])
match = lambda x: bool(re.match(*x))
pd.concat([s1.str.join('.*'), s2], axis=1).T.apply(match)
0 True
1 False
dtype: ... | 2 | 2016-10-19T04:51:35Z | [
"python",
"pandas"
] |
How to find 5 consecutive increasing/decreasing key/value pairs in dict based on the value | 40,121,905 | <p>I am a DBA and trying to get some data as per management request. I am also new to python.
I have input like below(Few hundreds of records) with out the headers Date and Value. I put this data into a dictionary (Date as key). Now I am trying to loop through the dictionary for trying to find any 5 consecutive rows wi... | 0 | 2016-10-19T04:02:48Z | 40,125,096 | <p>The following approach should work for Python 2. It is best to work with the data as a list ordered by date, so it first converts the dictionary into an ordered list based on the dates.</p>
<p>It then creates a list comparing each adjacent entry, if it ascends it stores <code>1</code>, equal <code>0</code> and desc... | 0 | 2016-10-19T07:41:58Z | [
"python",
"date",
"dictionary",
"collections"
] |
Wrong output when trying to print out mouse position | 40,121,925 | <p>I'm trying to make a function which continually prints out the mouse position constantly until stopped.
import pyautogui</p>
<pre><code>import pyautogui
print('Press CTRL + "c" to stop')
while True:
try:
x, y = pyautogui.position()
positionStr = 'X: ' + str(x).rjust(4) + ' Y: ' + str(y).rjust(... | 1 | 2016-10-19T04:04:40Z | 40,122,096 | <p>You are not backspacing enough characters. You forgot to account for the extra space "end" character. Of course you should be able to leave out the <code>end</code> parameter entirely.</p>
| 1 | 2016-10-19T04:23:53Z | [
"python",
"debugging",
"pyautogui"
] |
Wrong output when trying to print out mouse position | 40,121,925 | <p>I'm trying to make a function which continually prints out the mouse position constantly until stopped.
import pyautogui</p>
<pre><code>import pyautogui
print('Press CTRL + "c" to stop')
while True:
try:
x, y = pyautogui.position()
positionStr = 'X: ' + str(x).rjust(4) + ' Y: ' + str(y).rjust(... | 1 | 2016-10-19T04:04:40Z | 40,122,177 | <p>You could print the line with a Carriage Return : </p>
<p>i.e. : </p>
<pre><code>print(positionStr + '\r'),
</code></pre>
<p>Like so, the next line will replace the existing one. And you'll always see one line updated with the new mouse position. </p>
<p>The full script :</p>
<pre><code>#!/usr/bin/env python
i... | 3 | 2016-10-19T04:31:49Z | [
"python",
"debugging",
"pyautogui"
] |
Python script to count pixel values fails on a less-than/greater-than comparison | 40,121,953 | <p>I wrote a short script to count the pixel values in an image:</p>
<pre><code>import os
import sys
import cv2
import numpy as np
imn = (sys.argv[1])
a = cv2.imread(imn, 0)
b = cv2.imread(imn, 1)
c = cv2.GaussianBlur(cv2.imread(imn, 0), (7,7), 2)
def NC(img):
y = img.reshape(1, -1)
numA = (y < 127.5).sum... | 0 | 2016-10-19T04:08:02Z | 40,128,144 | <p>There are a couple of issues with your approach.</p>
<p>When you do</p>
<pre><code>(y < 85.00).sum()
</code></pre>
<p>You're actually summing over the truth condition. So you end up counting where the condition evaluates to <code>True</code>. You can easily see it with a quick example:</p>
<pre><code>In [6]: ... | 1 | 2016-10-19T10:02:28Z | [
"python",
"arrays",
"numpy",
"operators",
"truthiness"
] |
Python SQLite TypeError | 40,121,980 | <pre><code>from sqlite3 import *
def insert_record(Who, Invented):
connection = connect(database = "activity.db")
internet = connection.cursor()
list = "INSERT INTO Information VALUES((Alexander_Graham, Phone))"
internet.execute(list)
rows_inserted = internet.rowcount
connection.commit()
... | -1 | 2016-10-19T04:12:01Z | 40,122,363 | <p>insert record is a function that takes two required arguments, which you didn't pass values in for.</p>
<pre><code>command = insert_record
</code></pre>
<p>A good example of this in action is the following test sequence:</p>
<pre><code>In [1]: def func(one,two):
...: return one+two
...:
In [2]: func()... | 0 | 2016-10-19T04:49:29Z | [
"python",
"sqlite"
] |
Python SQLite TypeError | 40,121,980 | <pre><code>from sqlite3 import *
def insert_record(Who, Invented):
connection = connect(database = "activity.db")
internet = connection.cursor()
list = "INSERT INTO Information VALUES((Alexander_Graham, Phone))"
internet.execute(list)
rows_inserted = internet.rowcount
connection.commit()
... | -1 | 2016-10-19T04:12:01Z | 40,122,395 | <p>When you press button then tkinter runs function <code>insert_record()</code> always without any arguments. </p>
<p>You have to define function without arguments too.</p>
<pre><code>def insert_record():
</code></pre>
<p>Or with with default values ie.</p>
<pre><code>def insert_record(Who=None, Invented=None):
<... | 0 | 2016-10-19T04:52:22Z | [
"python",
"sqlite"
] |
Python: find a series of Chinese characters within a string and apply a function | 40,122,058 | <p>I've got a series of text that is mostly English, but contains some phrases with Chinese characters. Here's two examples:</p>
<pre><code>s1 = "You say: ä½ å¥½. I say: åè¦"
s2 = "çæ¡, my friend, å¨é¢¨å¨å¹"
</code></pre>
<p>I'm trying to find each block of Chinese, apply a function which will translate the ... | 1 | 2016-10-19T04:19:08Z | 40,122,136 | <p>A possible solution is to capture everything, but in different capture groups, so you can differentiate later if they're in Chinese or not.</p>
<pre><code>ret = re.findall(ur'([\u4e00-\u9fff]+)|([^\u4e00-\u9fff]+)', utf_line)
result = []
for match in ret:
if match[0]:
result.append(translate(match[0]))
... | 2 | 2016-10-19T04:27:59Z | [
"python",
"regex"
] |
Python: find a series of Chinese characters within a string and apply a function | 40,122,058 | <p>I've got a series of text that is mostly English, but contains some phrases with Chinese characters. Here's two examples:</p>
<pre><code>s1 = "You say: ä½ å¥½. I say: åè¦"
s2 = "çæ¡, my friend, å¨é¢¨å¨å¹"
</code></pre>
<p>I'm trying to find each block of Chinese, apply a function which will translate the ... | 1 | 2016-10-19T04:19:08Z | 40,122,721 | <p>Regular expression <code>Match</code> objects give you the start and end indexes of a match. So, instead of <code>findall</code>, do your own search and record the indexes as you go. Then, you can translate each extent and replace in the string based on the known indexes of the phrases.</p>
<pre><code>import re
_s... | 0 | 2016-10-19T05:17:26Z | [
"python",
"regex"
] |
Python: find a series of Chinese characters within a string and apply a function | 40,122,058 | <p>I've got a series of text that is mostly English, but contains some phrases with Chinese characters. Here's two examples:</p>
<pre><code>s1 = "You say: ä½ å¥½. I say: åè¦"
s2 = "çæ¡, my friend, å¨é¢¨å¨å¹"
</code></pre>
<p>I'm trying to find each block of Chinese, apply a function which will translate the ... | 1 | 2016-10-19T04:19:08Z | 40,122,744 | <p>You could always use a in-place replace of the matched regular expression by using <code>re.sub()</code> in python.</p>
<p>Try this:</p>
<pre><code>print(re.sub(r'([\u4e00-\u9fff]+)', translate('\g<0>'), utf_line))
</code></pre>
| 3 | 2016-10-19T05:19:05Z | [
"python",
"regex"
] |
Python: find a series of Chinese characters within a string and apply a function | 40,122,058 | <p>I've got a series of text that is mostly English, but contains some phrases with Chinese characters. Here's two examples:</p>
<pre><code>s1 = "You say: ä½ å¥½. I say: åè¦"
s2 = "çæ¡, my friend, å¨é¢¨å¨å¹"
</code></pre>
<p>I'm trying to find each block of Chinese, apply a function which will translate the ... | 1 | 2016-10-19T04:19:08Z | 40,122,821 | <p>You can't get the indexes using <a href="https://docs.python.org/2/library/re.html#re.findall" rel="nofollow">re.findall()</a>. You could use <a href="https://docs.python.org/2/library/re.html#re.finditer" rel="nofollow">re.finditer()</a> instead, and refer to <a href="https://docs.python.org/2/library/re.html#re.Ma... | 2 | 2016-10-19T05:24:54Z | [
"python",
"regex"
] |
Why sparse matrix computing on python is too slow | 40,122,077 | <p>The format I have used is the csr sparse matrix, which is recommended to be the fastest sparse structure for add and dot opertor. I compared its performance with the add and dot operator of np.array. However, it seems very weird that the computing for sparse matrix is much slower than the case under dense format. Wh... | 2 | 2016-10-19T04:21:41Z | 40,122,715 | <p>Both sets of operations use compiled code. But the data is stored quite differently.</p>
<p><code>x.shape</code> is (10000,); <code>y</code> likewise. <code>x+y</code> just has to allocate an array of the same shape, and efficiently in <code>c</code> step through the 3 data buffers.</p>
<p><code>x_sp</code> has 2... | 1 | 2016-10-19T05:17:13Z | [
"python",
"performance",
"numpy",
"scipy",
"sparse-matrix"
] |
Deleting lines in python | 40,122,192 | <p>I was just wondering how to delete lines in python.</p>
<p>Firstly I have opened up the csv file (using the with statements and whatnot), however the first couple of lines are unneccessary. They go along the lines of this:</p>
<p>**version 2.0 keyboard strokes</p>
<p>version 1.5 mouse wheel</p>
<p>... ..**... | 1 | 2016-10-19T04:32:51Z | 40,122,254 | <p>You can prompt the user with a simple while loop and listen into <a href="https://docs.python.org/3/library/sys.html#sys.stdin" rel="nofollow">standard input</a> or using the <a href="https://docs.python.org/3/library/functions.html#input" rel="nofollow">input()</a> function. </p>
<p>As to your question on how to d... | 0 | 2016-10-19T04:39:09Z | [
"python",
"csv"
] |
Deleting lines in python | 40,122,192 | <p>I was just wondering how to delete lines in python.</p>
<p>Firstly I have opened up the csv file (using the with statements and whatnot), however the first couple of lines are unneccessary. They go along the lines of this:</p>
<p>**version 2.0 keyboard strokes</p>
<p>version 1.5 mouse wheel</p>
<p>... ..**... | 1 | 2016-10-19T04:32:51Z | 40,122,298 | <p>There are quite a few ways to grab input from a command line tool (which is what I am inferring you wrote). Here are a couple:</p>
<p><em>Option 1:</em> created in a file called out.py
use sys.argv</p>
<pre><code>import sys
arg1 = sys.argv[1]
print("passed in value: %s" % arg1)
</code></pre>
<p>Then run it by p... | 0 | 2016-10-19T04:43:21Z | [
"python",
"csv"
] |
Deleting lines in python | 40,122,192 | <p>I was just wondering how to delete lines in python.</p>
<p>Firstly I have opened up the csv file (using the with statements and whatnot), however the first couple of lines are unneccessary. They go along the lines of this:</p>
<p>**version 2.0 keyboard strokes</p>
<p>version 1.5 mouse wheel</p>
<p>... ..**... | 1 | 2016-10-19T04:32:51Z | 40,122,350 | <p>Use <a href="https://docs.python.org/3/library/fileinput.html#fileinput.input" rel="nofollow"><code>fileinput.input()</code></a> with the inplace update file option:</p>
<pre><code>from __future__ import print_function
import fileinput
skip_rows = int(input('How many rows to skip? '))
f = fileinput.input('input.cs... | 0 | 2016-10-19T04:48:30Z | [
"python",
"csv"
] |
Deleting lines in python | 40,122,192 | <p>I was just wondering how to delete lines in python.</p>
<p>Firstly I have opened up the csv file (using the with statements and whatnot), however the first couple of lines are unneccessary. They go along the lines of this:</p>
<p>**version 2.0 keyboard strokes</p>
<p>version 1.5 mouse wheel</p>
<p>... ..**... | 1 | 2016-10-19T04:32:51Z | 40,122,525 | <blockquote>
<p>Firstly I have opened up the csv file [...]</p>
</blockquote>
<p>Did you consider to use <a href="http://pandas.pydata.org/" rel="nofollow">pandas</a> to process your data?<br>
If so, <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html" rel="nofollow">pandas.read_csv</... | 0 | 2016-10-19T05:02:40Z | [
"python",
"csv"
] |
Deleting lines in python | 40,122,192 | <p>I was just wondering how to delete lines in python.</p>
<p>Firstly I have opened up the csv file (using the with statements and whatnot), however the first couple of lines are unneccessary. They go along the lines of this:</p>
<p>**version 2.0 keyboard strokes</p>
<p>version 1.5 mouse wheel</p>
<p>... ..**... | 1 | 2016-10-19T04:32:51Z | 40,122,865 | <p>You will typically use an iterator to read files. You could do something like this:</p>
<pre><code>numToSkip = 3
with open('somefile.txt') as f:
for i, line in enumerate(f):
if i < numToSkip : continue
# Do 'whatnot' processing here
</code></pre>
| 0 | 2016-10-19T05:27:38Z | [
"python",
"csv"
] |
Submitting large directories in perforce | 40,122,226 | <p>I would like to know unix command to submit large directories in perforce. we use p4 submit to submit files in the depot. But in the case of directories what is the command to put it in depot in a single shot.</p>
| -1 | 2016-10-19T04:36:31Z | 40,123,083 | <p>It's still just:</p>
<pre><code>p4 submit
</code></pre>
<p>to submit everything open in your default changelist.</p>
<p>If you want to submit all the files under a specific directory, but leave all other files open, do:</p>
<pre><code>p4 submit directory/...
</code></pre>
| 1 | 2016-10-19T05:43:29Z | [
"python",
"unix",
"perforce"
] |
Python : Check an inputs first characters | 40,122,354 | <p>Okay so i have a problem i looked it up but didnt know exactly what to look up and kept seeing problems that had nothing to do with mine.. So my problem here is im taking an input in python</p>
<pre><code>flashSite = raw_input('[?] Please Provide a Web Url : ')
</code></pre>
<p>After it takes the input i want it t... | 0 | 2016-10-19T04:48:52Z | 40,122,477 | <p>raw_input returns a string, as visible from the documentation: <a href="https://docs.python.org/2/library/functions.html#" rel="nofollow">https://docs.python.org/2/library/functions.html#</a></p>
<p>Since you're working with a string Type, you can use any of the string methods <a href="https://docs.python.org/2/lib... | 1 | 2016-10-19T04:59:33Z | [
"python",
"input",
"character"
] |
How to separately plot the figures in one big single figure using matplotlib? | 40,122,557 | <p>I have just started learning <code>Python</code>, I am analyzing a data from <code>.csv</code> file and I want to separate figures, but I am getting all the plots in one graph and I am not able to separate the graphs. Please help!</p>
<pre><code>n = 10
i=0
for i in range(0,n):
inflammation = matplotlib.pyplot.p... | 0 | 2016-10-19T05:05:02Z | 40,122,904 | <p>Just use a new <code>figure()</code></p>
<pre><code>n = 10
i=0
for i in range(0,n):
matplotlib.pyplot.figure()
inflammation = matplotlib.pyplot.plot(data[i,:40]) #inflammation graph for patient 0
</code></pre>
<p>Each figure uses a lot of memory. So use it sparingly. Learn about <code>clf()</code> and <cod... | 1 | 2016-10-19T05:31:32Z | [
"python",
"matplotlib"
] |
How to separately plot the figures in one big single figure using matplotlib? | 40,122,557 | <p>I have just started learning <code>Python</code>, I am analyzing a data from <code>.csv</code> file and I want to separate figures, but I am getting all the plots in one graph and I am not able to separate the graphs. Please help!</p>
<pre><code>n = 10
i=0
for i in range(0,n):
inflammation = matplotlib.pyplot.p... | 0 | 2016-10-19T05:05:02Z | 40,124,306 | <p>You could always take a look at using <a href="http://matplotlib.org/api/pyplot_api.html?highlight=subplot#matplotlib.pyplot.subplot" rel="nofollow"><code>subplot()</code></a>, which would work as follows:</p>
<pre><code>import matplotlib.pyplot as plt
for n in range(1, 11):
plt.subplot(2, 5, n)
plt.plot(r... | 1 | 2016-10-19T06:59:49Z | [
"python",
"matplotlib"
] |
tcp python socket hold connection forever | 40,122,639 | <p>I have a client-server model where the client will constantly checking a log file and as soon as a new line comes in the log file it sends that line to the server. </p>
<p>Somehow I managed to work this thing using the following code.</p>
<p><strong>server.py</strong></p>
<pre><code>import SocketServer
class My... | 0 | 2016-10-19T05:11:36Z | 40,125,999 | <p>After a line is transmitted, you close the connection on the client, but don't close it on the server.</p>
<p>From <a href="https://docs.python.org/3.4/library/socketserver.html#socketserver.RequestHandler.finish" rel="nofollow">the docs</a>:</p>
<blockquote>
<p>RequestHandler.finish()</p>
<p>Called after t... | 0 | 2016-10-19T08:28:08Z | [
"python",
"sockets",
"tcp"
] |
Correct way of sending JSON Data with encoding in Python | 40,122,684 | <p>I am developing API's on Django, and I am facing a lot of issues in encoding the data in python at the back-end and decoding it at front-end on java. </p>
<p>Any standard rules for sending correct JSON Data to client application efficiently? </p>
<p>There are some Hindi Characters which are not received properly o... | 0 | 2016-10-19T05:15:23Z | 40,122,847 | <p><code>json.loads</code> and <code>json.dumps</code> are generally used to encode and decode JSON data in python. </p>
<p><code>dumps</code> takes an object and produces a string and <code>load</code> would take a file-like object, read the data from that object, and use that string to create an object. </p>
<p>T... | 3 | 2016-10-19T05:26:19Z | [
"python",
"json",
"django"
] |
Syntax error Jython | 40,122,712 | <p>I am getting a syntax error in my code. Can anyone say what's wrong in the syntax? I am new to this language, don't have much of an idea.</p>
<p>Error message</p>
<blockquote>
<p>WASX7017E: Exception received while running file "JDBCoracle.py"; exception information: com.ibm.bsf.BSFException: exception from Jyth... | -1 | 2016-10-19T05:17:11Z | 40,123,839 | <p>Your error is the comma in <code>def OracleJDBC(cellName,serverName,):</code>; eliminate it and things will work. </p>
<pre><code>import sys
## **JDBCProvider** ##
def OracleJDBC(cellName,serverName):
name ="Oracle JDBC Driver"
print " Name of JDBC Provider which will be created ---> " + name
print... | 1 | 2016-10-19T06:32:25Z | [
"python",
"jython"
] |
How to know which is more advatageous with assigning same value to different attributes in python | 40,122,713 | <p>Between the two in python which will be faster and advatageous</p>
<pre><code>a = b = c = d = 1
</code></pre>
<p>and</p>
<pre><code>a = 1
b = 1
c = 1
d = 1
</code></pre>
| 3 | 2016-10-19T05:17:11Z | 40,122,792 | <p>Simply run a test:</p>
<pre><code>>>> import timeit
>>> min(timeit.repeat('a = b = c = d = 1', number=10000000))
0.4885740280151367
>>> min(timeit.repeat('a = 1; b = 1; c = 1; d = 1', number=10000000))
0.6283371448516846
</code></pre>
<p>Also note:</p>
<pre><code>>>> min(timeit... | 5 | 2016-10-19T05:22:44Z | [
"python",
"python-2.7"
] |
python url not found - Accessing views.py from AJAX | 40,122,717 | <p>New to Python and Django and I'm trying to make a simple ajax call from a button click to pass certain data to my views.py, however, when I try to make a url as seen on my ajax code below, the <code>documentId.id</code> does not append unless I directly append in without the <code>"?id="</code>.</p>
<pre><code> ... | 0 | 2016-10-19T05:17:15Z | 40,122,793 | <p>In JavaScript you need </p>
<pre><code>"upload-data/load/" + documentId.id
</code></pre>
<p>Django doesn't use <code>?id=</code> in <code>url</code> definition <code>r^"upload-data/load/([0-9]+)/$'</code>. It expects ie. <code>upload-data/load/123</code> instead of <code>upload-data/load?id=123</code></p>
<hr>
<... | 0 | 2016-10-19T05:22:48Z | [
"python",
"ajax",
"django",
"url",
"onclick"
] |
python url not found - Accessing views.py from AJAX | 40,122,717 | <p>New to Python and Django and I'm trying to make a simple ajax call from a button click to pass certain data to my views.py, however, when I try to make a url as seen on my ajax code below, the <code>documentId.id</code> does not append unless I directly append in without the <code>"?id="</code>.</p>
<pre><code> ... | 0 | 2016-10-19T05:17:15Z | 40,123,186 | <p>Use something like this:</p>
<pre><code>def loadFile(request):
documentId= request.GET.get('id', '').
newLayer = Layer(get_object_or_404(Document, pk = documentId))
newLayer.save()
layers = Layer.objects.all()
return render(request, 'url/loaded.html', { 'layers': layers})
</code></pre>
<p>And ... | 1 | 2016-10-19T05:49:20Z | [
"python",
"ajax",
"django",
"url",
"onclick"
] |
python url not found - Accessing views.py from AJAX | 40,122,717 | <p>New to Python and Django and I'm trying to make a simple ajax call from a button click to pass certain data to my views.py, however, when I try to make a url as seen on my ajax code below, the <code>documentId.id</code> does not append unless I directly append in without the <code>"?id="</code>.</p>
<pre><code> ... | 0 | 2016-10-19T05:17:15Z | 40,123,858 | <p>From the above answers and comments it seems like rather than passing id as a <code>url param</code> you want to pass the same as a <code>get param</code>. In that case make your urls like below.</p>
<pre><code>url(r^"upload-data/load/', views.loadFile, name="load-data")
</code></pre>
<p>and in views, check for ge... | 0 | 2016-10-19T06:33:45Z | [
"python",
"ajax",
"django",
"url",
"onclick"
] |
File Upload dialog is not picked by selenium | 40,122,813 | <p><a href="https://i.stack.imgur.com/oBL4R.png" rel="nofollow"><img src="https://i.stack.imgur.com/oBL4R.png" alt="enter image description here"></a></p>
<p>I am trying to write a selenium based test in python.
Here, I am trying to select a file for the first text box(<code>PGP Private Key</code>)</p>
<p>Please note... | 0 | 2016-10-19T05:24:36Z | 40,125,704 | <p>In common case this code should work:</p>
<pre><code>driver.find_element_by_xpath("//input[@id='selectKeys']").send_keys(path_to_file)
</code></pre>
| 0 | 2016-10-19T08:12:58Z | [
"python",
"selenium",
"firefox",
"firebug",
"inspector"
] |
Alternate for range in python | 40,122,852 | <p>If I have to generate natural numbers, I can use 'range' as follows:</p>
<pre><code>list(range(5))
</code></pre>
<p>[0, 1, 2, 3, 4]</p>
<p>Is there any way to achieve this without using range function or looping?</p>
| -1 | 2016-10-19T05:26:44Z | 40,123,004 | <p>You could use recursion to print first n natural numbers</p>
<pre><code>def printNos(n):
if n > 0:
printNos(n-1)
print n
printNos(100)
</code></pre>
| 4 | 2016-10-19T05:38:10Z | [
"python"
] |
Alternate for range in python | 40,122,852 | <p>If I have to generate natural numbers, I can use 'range' as follows:</p>
<pre><code>list(range(5))
</code></pre>
<p>[0, 1, 2, 3, 4]</p>
<p>Is there any way to achieve this without using range function or looping?</p>
| -1 | 2016-10-19T05:26:44Z | 40,123,057 | <p>Looping will be required in some form or another to generate a list of numbers, whether you do it yourself, use library functions, or use recursive methods.</p>
<p>If you're not opposed to looping in principle (but just don't want to implement it yourself), there are many practical and esoteric ways to do it (a num... | 2 | 2016-10-19T05:41:49Z | [
"python"
] |
Alternate for range in python | 40,122,852 | <p>If I have to generate natural numbers, I can use 'range' as follows:</p>
<pre><code>list(range(5))
</code></pre>
<p>[0, 1, 2, 3, 4]</p>
<p>Is there any way to achieve this without using range function or looping?</p>
| -1 | 2016-10-19T05:26:44Z | 40,123,095 | <p>Based on Nihal's solution, but returns a list instead:</p>
<pre><code>def recursive_range(n):
if n == 0:
return []
return recursive_range(n-1) + [n-1]
</code></pre>
| 2 | 2016-10-19T05:44:00Z | [
"python"
] |
Alternate for range in python | 40,122,852 | <p>If I have to generate natural numbers, I can use 'range' as follows:</p>
<pre><code>list(range(5))
</code></pre>
<p>[0, 1, 2, 3, 4]</p>
<p>Is there any way to achieve this without using range function or looping?</p>
| -1 | 2016-10-19T05:26:44Z | 40,123,211 | <p>Well, yes, you can do this without using <code>range</code>, loop or recursion:</p>
<pre><code>>>> num = 10
>>> from subprocess import call
>>> call(["seq", str(num)])
</code></pre>
<p>You can even have a list (or a generator, of course):</p>
<pre><code>>>> num = 10
>>>... | 2 | 2016-10-19T05:50:53Z | [
"python"
] |
How to connect 2 ultrasonic sensors concurrently using python multiprocessing process? | 40,123,068 | <p>I'm new to python but i'm working on a project in which i need to connect 3 or more Ultrasonic Sensors concurrently. I read all about threads and multiprocessing ran a couple of examples successfully. I know the code has to be run form the command prompt or the PI2 terminal. However, the multiprocessing code I wrote... | 0 | 2016-10-19T05:42:48Z | 40,128,355 | <p>You do not say what you mean with "does not work", so I am taking a few guesses here.</p>
<p>The obvious fail here would be:</p>
<blockquote>
<p>TypeError: A() takes exactly 1 argument (0 given)</p>
</blockquote>
<p>Since functions <code>A</code>, <code>B</code> and <code>C</code> all take an argument <code>nam... | 0 | 2016-10-19T10:11:15Z | [
"python"
] |
Keras - input shape of large 2-dimensional Array | 40,123,070 | <p>I want to build an array which contains a very large number of elements
number of sequences (batch size) * size of dictionary (unique words in file)
474683 * 22995</p>
<p>each sequence will have some number X of bits turned on which represents a word in the dictionary</p>
<p>the sentence is: "I am the best king"
l... | 0 | 2016-10-19T05:43:00Z | 40,123,655 | <p>Okay, I decided to split the array and train on each of the split instead of pushing everything to memory:</p>
<pre><code>data_cut = 3
X = np.zeros((len(inputs)/data_cut, max_len, len(words)), dtype=np.bool)
y = np.zeros((len(inputs)/data_cut, len(words)), dtype=np.bool)
# set the appropriate indices to 1 in eac... | 0 | 2016-10-19T06:20:58Z | [
"python",
"arrays",
"keras"
] |
python loop to find the largest integer from a list | 40,123,112 | <p>I wrote a script to pull down a list of aws tags and then read the last octect and tell me which one is the highest IP. For example. here is the list of tags that are returned:</p>
<p>['vlslabmc, 172.16.0.13/24', 'vlslabmc,172.16.0.5/24', 'vlslabmc,172.16.0.3/24', 'vlslabmc,172.16.0.12/24', 'vlslabmc,172.16.0.16/24... | 1 | 2016-10-19T05:44:57Z | 40,123,380 | <p>So I had to refactor your code a little bit. I assumed ipList was an empty list. Are you sure you tested to see if it actually ran? Specifically your if statement</p>
<pre><code>if int(latestIP) > largestIP:
largestIP = latestIP
</code></pre>
<p>would return a</p>
<pre><code>TypeError: unorderable types: i... | 0 | 2016-10-19T06:01:46Z | [
"python",
"list",
"loops",
"integer"
] |
python loop to find the largest integer from a list | 40,123,112 | <p>I wrote a script to pull down a list of aws tags and then read the last octect and tell me which one is the highest IP. For example. here is the list of tags that are returned:</p>
<p>['vlslabmc, 172.16.0.13/24', 'vlslabmc,172.16.0.5/24', 'vlslabmc,172.16.0.3/24', 'vlslabmc,172.16.0.12/24', 'vlslabmc,172.16.0.16/24... | 1 | 2016-10-19T05:44:57Z | 40,123,446 | <p>Why are doing this so complex. Here is oneliner for this</p>
<pre><code>ip_list = ['vlslabmc, 172.16.0.13/24', 'vlslabmc,172.16.0.5/24', 'vlslabmc,172.16.0.3/24', 'vlslabmc,172.16.0.12/24', 'vlslabmc,172.16.0.16/24', 'vlslabmc,172.16.0.6/24', 'vlslabmc,172.16.0.1/24', 'vlslabmc,172.16.0.11/24', 'vlslabmc,172.16.0.1... | 1 | 2016-10-19T06:06:25Z | [
"python",
"list",
"loops",
"integer"
] |
python loop to find the largest integer from a list | 40,123,112 | <p>I wrote a script to pull down a list of aws tags and then read the last octect and tell me which one is the highest IP. For example. here is the list of tags that are returned:</p>
<p>['vlslabmc, 172.16.0.13/24', 'vlslabmc,172.16.0.5/24', 'vlslabmc,172.16.0.3/24', 'vlslabmc,172.16.0.12/24', 'vlslabmc,172.16.0.16/24... | 1 | 2016-10-19T05:44:57Z | 40,123,538 | <p>The code is quite convoluted (much more than needed) but the error is that <code>ipList</code> gets filled with strings and then its elements are compared with an integer.</p>
<p>This in Python 2 was a silent source of problems (you got a nonsensical but stable <code>True</code>/<code>False</code> result when compa... | 1 | 2016-10-19T06:13:22Z | [
"python",
"list",
"loops",
"integer"
] |
python loop to find the largest integer from a list | 40,123,112 | <p>I wrote a script to pull down a list of aws tags and then read the last octect and tell me which one is the highest IP. For example. here is the list of tags that are returned:</p>
<p>['vlslabmc, 172.16.0.13/24', 'vlslabmc,172.16.0.5/24', 'vlslabmc,172.16.0.3/24', 'vlslabmc,172.16.0.12/24', 'vlslabmc,172.16.0.16/24... | 1 | 2016-10-19T05:44:57Z | 40,123,866 | <p>Although other people have already provide you some alternative ways to find the answer, if you want to keep using your program, here is some way of fixing it:</p>
<pre><code>def findLargestIP():
ipList = []
for i in tagList:
#remove all the spacing in the tags
ec2Tags = i.strip()
#s... | 2 | 2016-10-19T06:34:21Z | [
"python",
"list",
"loops",
"integer"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.