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
Printing all solutions in the shape of a matrix using \n\
37,641,035
<p>This function returns all possible multiplication from 1 to d. I want to print the solution in the shape of a d×d matrix. </p> <pre><code>def example(d): for i in range(1,d+1): for l in range(1,d+1): print(i*l) </code></pre> <p>For <code>d = 5</code>, the expected output should look like: </p> ...
0
2016-06-05T10:53:31Z
37,641,093
<p>Try this: </p> <pre><code>mm = [] ll = [] def mul(d): for i in range(1,d+1): ll = [] for l in range(1,d+1): # print(i*l), ll.append((i*l)) mm.append(ll) mul(5) for x in mm: print(x) [1, 2, 3, 4, 5] [2, 4, 6, 8, 10] [3, 6, 9, 12, 15] [4, 8, 12, 16, 20] [5, ...
0
2016-06-05T11:00:16Z
[ "python" ]
Printing all solutions in the shape of a matrix using \n\
37,641,035
<p>This function returns all possible multiplication from 1 to d. I want to print the solution in the shape of a d×d matrix. </p> <pre><code>def example(d): for i in range(1,d+1): for l in range(1,d+1): print(i*l) </code></pre> <p>For <code>d = 5</code>, the expected output should look like: </p> ...
0
2016-06-05T10:53:31Z
37,641,126
<p>You could add the values in your second for loop to a list, <code>join</code> the list, and finally print it.</p> <pre><code>def mul(d): for i in range(1, d+1): list_to_print = [] for l in range(1, d+1): list_to_print.append(str(l*i)) print(" ".join(list_to_print)) &gt;&gt;&...
0
2016-06-05T11:05:26Z
[ "python" ]
Python - django: Reading multiple request params for making queries
37,641,086
<p>I have just started hands-on on Python-django</p> <p>I am trying filter objects from DB using queries in django view. Three params are passed from the url and I want to do a 'or' condition on the params. Few params can be null.</p> <pre><code> if 'custName' in request.GET : custName = request.GET['custName...
1
2016-06-05T10:59:45Z
37,641,173
<p>If <code>'custId' in request.GET and request.GET['custId']</code> is false then <code>files_id</code> never gets defined, yet you want to refer to it unconditionally. So you must define a default value (e.g. <code>set()</code>) before the condition to ensure that it is always defined.</p> <p>Your code can be hugely...
0
2016-06-05T11:11:58Z
[ "python", "django", "django-queryset" ]
Passing Python functions as objects to Spark
37,641,103
<p>I've been playing with Spark and Python on this online jupyter notebook <a href="https://tmpnb.org/">https://tmpnb.org/</a> and tried 3 ways to pass python functions:</p> <p>1) using map</p> <pre><code>import numpy as np def my_sqrt(x): return np.sqrt(x) sc.parallelize(range(10)).map(my_sqrt).collect() </code...
5
2016-06-05T11:01:44Z
37,641,720
<p><strong>The first</strong> approach works because Spark is using special serialization strategy to process closures required for transformations which is significantly slower but more powerful than the standard <code>pickle</code> (otherwise we couldn't use <code>.map(lambda x: ...)</code>).</p> <p><strong>The last...
6
2016-06-05T12:09:15Z
[ "python", "apache-spark", "pyspark" ]
googlemaps-2.4.3-py2-none-any.whl is not a supported wheel on this platform
37,641,128
<p>I am trying to install googlemaps module (from <a href="https://pypi.python.org/pypi/googlemaps/" rel="nofollow">here</a>). using:</p> <pre><code>pip install "googlemaps-2.4.3-py2-none-any.whl" </code></pre> <p>I get the following error:</p> <p>googlemaps-2.4.3-py2-none-any.whl is not a supported wheel on this pl...
-1
2016-06-05T11:05:43Z
37,641,175
<p>Why that particular version? Does <code>pip install googlemaps</code>, which is version 2.4.3 currently, not satisfy your needs?</p>
0
2016-06-05T11:12:07Z
[ "python", "google-maps-api-3", "pip" ]
How to run reset_db from django-extensions on Heroku ? Fails with: "User does not have CONNECT privilege."
37,641,289
<p>I can do database operations like <code>heroku run python manage.py migrate</code> normally, but <code>reset_db</code> fails with:</p> <pre><code>Traceback (most recent call last): File "manage.py", line 10, in &lt;module&gt; execute_from_command_line(sys.argv) File "/app/.heroku/python/lib/python3.5/site-p...
0
2016-06-05T11:23:42Z
37,689,402
<p>Do not use <code>reset_db</code> command - it executes both a "drop" and "create", which I suspect don't quite work with the permissions Heroku grants. Better is to use the built-in Heroku command <code>pg:reset</code>. For example: <code>heroku pg:reset DATABASE_URL</code>. See <a href="https://devcenter.heroku.com...
1
2016-06-07T21:09:18Z
[ "python", "django", "heroku", "django-extensions" ]
How to remove certain characters from lists (Python 2.7)?
37,641,375
<p>I've got a list where each element is:</p> <pre><code>['a ',' b ',' c ',' d\n '] </code></pre> <p>I want to manipulate it so that each element just becomes:</p> <pre><code>['a','b','c','d'] </code></pre> <p>I don't think the spaces matter, but for some reason I can't seem to remove the \n from the end of the 4th...
0
2016-06-05T11:32:49Z
37,641,385
<p>Try this -</p> <pre><code>arr = ['a ',' b ',' c ',' d\n '] arr = [s.strip() for s in arr] </code></pre>
1
2016-06-05T11:34:38Z
[ "python", "string", "list", "replace", "strip" ]
How to remove certain characters from lists (Python 2.7)?
37,641,375
<p>I've got a list where each element is:</p> <pre><code>['a ',' b ',' c ',' d\n '] </code></pre> <p>I want to manipulate it so that each element just becomes:</p> <pre><code>['a','b','c','d'] </code></pre> <p>I don't think the spaces matter, but for some reason I can't seem to remove the \n from the end of the 4th...
0
2016-06-05T11:32:49Z
37,641,396
<pre><code>&gt;&gt;&gt; my_array = ['a ',' b ',' c ',' d\n '] &gt;&gt;&gt; my_array = [c.strip() for c in my_array] &gt;&gt;&gt; my_array ['a', 'b', 'c', 'd'] </code></pre> <p>If you have a list of arrays then you can do something in the lines of:</p> <pre><code>&gt;&gt;&gt; list_of_arrays = [['a', 'b', 'c', 'd'], ['...
3
2016-06-05T11:35:38Z
[ "python", "string", "list", "replace", "strip" ]
How to remove certain characters from lists (Python 2.7)?
37,641,375
<p>I've got a list where each element is:</p> <pre><code>['a ',' b ',' c ',' d\n '] </code></pre> <p>I want to manipulate it so that each element just becomes:</p> <pre><code>['a','b','c','d'] </code></pre> <p>I don't think the spaces matter, but for some reason I can't seem to remove the \n from the end of the 4th...
0
2016-06-05T11:32:49Z
37,642,890
<p>A very simple answer is join your list, strip the nextline charcter and split to get a new list:</p> <p>Newlist = ''.join(myList).strip().split()</p> <p>Your Newlist is now:</p> <p>['a', 'b', 'c', 'd']</p>
0
2016-06-05T14:14:27Z
[ "python", "string", "list", "replace", "strip" ]
Win7 64bit cx_Oracle cx_Oracle.pyd not found
37,641,413
<p>I'm trying to connect to an Oracle DB 11.2g from Python 3.5. I tried my luck with cx_Oracle. Other means are welcome if you have a better option. Here you can see that I have tried many routes to my cause.</p> <p>I downloaded MS Windows installer 3.5 from <a href="https://pypi.python.org/pypi/cx_Oracle/5.2.1" rel="...
0
2016-06-05T11:37:01Z
39,745,905
<p>You can get 11g cx here: <a href="https://sourceforge.net/directory/os:windows/?q=cx_oracle-11g" rel="nofollow">https://sourceforge.net/directory/os:windows/?q=cx_oracle-11g</a> </p> <p>At first glance it seems that you are telling your library to work from the document folder which means that you have to go into t...
-1
2016-09-28T11:16:24Z
[ "python", "windows", "oracle" ]
Receiving ajax posted object in django view
37,641,471
<p>needless to say i'm a rookie ! so here is my js code which send a js object via ajax to a view </p> <pre><code>function test(){ arr = {} ; $('#settings_tab').find('.someclass').each(function(index, element) { key = $(this).attr('id') ; value = $(this).val(); arr[key] = value; }); ...
1
2016-06-05T11:43:51Z
37,642,032
<p>you need to serialize your object to json string first: </p> <pre><code>$.post("{% url 'setting-update' %}" , { arr: JSON.stringify(arr), // &lt;----------- csrfmiddlewaretoken : '{{ csrf_token }}' }, function(){alert('done!')} }); </code></pre> <p>then in views.py</p> <pre><code...
1
2016-06-05T12:42:03Z
[ "javascript", "jquery", "python", "django" ]
Receiving ajax posted object in django view
37,641,471
<p>needless to say i'm a rookie ! so here is my js code which send a js object via ajax to a view </p> <pre><code>function test(){ arr = {} ; $('#settings_tab').find('.someclass').each(function(index, element) { key = $(this).attr('id') ; value = $(this).val(); arr[key] = value; }); ...
1
2016-06-05T11:43:51Z
37,642,072
<p>Two things to take note of there, first of all, JQuery is flattening your data-structure. For each element in your dictionary (that is, your <code>arr</code> variable), it creates a element in the <code>QueryDict</code> with a unique key. </p> <p>So, </p> <pre><code>var arr = {'one': 'data1', 'two': 'data2'}; </co...
1
2016-06-05T12:45:48Z
[ "javascript", "jquery", "python", "django" ]
Is there a difference in the way we access elements of a list comprehension and the elements of a numpy array
37,641,494
<p>I am working on a genetic algorithm code. I am fairly new to python. My code snippet is as follows:</p> <pre><code> import numpy as np pop_size = 10 # Population size noi = 2 # Number of Iterations M = 2 # Number of Phases in the Data alpha = [np.random.randint(0, 64...
-1
2016-06-05T11:45:48Z
37,643,733
<p>There some questionable programming in these 2 lines</p> <pre><code> alpha = [np.random.randint(0, 64, size = pop_size)]* M ... alpha_en = [(2*np.pi*alpha/63.00) for alpha in alpha] </code></pre> <p>The first makes an array, and then makes a list with <code>M</code> pointers to the same thing. Note, M ...
2
2016-06-05T15:43:06Z
[ "python", "numpy", "matrix", "list-comprehension" ]
winpdb is not recognising function inputs?
37,641,499
<p>This is my first post! :D </p> <p>I am trying to learn how to use winpdb to debug some python code and have a problem. Consider the following python function, simple.py: </p> <pre><code> def simple(a,b): c = a + b return c </code></pre> <p>I am in windows and using the command line in the directory ...
0
2016-06-05T11:46:09Z
38,214,513
<p>The presented source file defines a function but it never calls the function and doesn't execute any code at all. Code in exactly that form can't be trivially debugged. Typically a sample call to function is added to the end of file, like</p> <pre><code>def simple(a, b): c = a + b return c simple(1, 2) </co...
0
2016-07-05T23:44:53Z
[ "python", "winpdb" ]
how to count the time from LOW to HIGH pin level in python
37,641,507
<p>i have this code right here:</p> <pre><code>import datetime import time import math import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO.setup(20,GPIO.IN) input = GPIO.input(20) #initialise a previous input variable to 0 (assume button not pressed last) prev_input = 0 D = 0.66 #wheel diameter while True: #t...
0
2016-06-05T11:46:31Z
37,641,598
<p>So you just put the time when the pin went to high in a variable. when you need to access the time you get the current time minus the variable you declared earlier.</p> <pre><code>if input: time_since_high = datetime.datetime.now() time_passed = datetime.datetime.now() - time_since_high </code></pre>
0
2016-06-05T11:55:53Z
[ "python", "time", "count" ]
how to count the time from LOW to HIGH pin level in python
37,641,507
<p>i have this code right here:</p> <pre><code>import datetime import time import math import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO.setup(20,GPIO.IN) input = GPIO.input(20) #initialise a previous input variable to 0 (assume button not pressed last) prev_input = 0 D = 0.66 #wheel diameter while True: #t...
0
2016-06-05T11:46:31Z
37,641,707
<p>You can do the following:</p> <pre><code>import time while input == 0: start = time.time() while input == 1: stop = time.time() # Calculate elapsed time elapsed = stop - start </code></pre> <p>This will poll the GPIO pin to see if the input changes from LOW to HIGH. It will then calculate the time it takes t...
0
2016-06-05T12:08:05Z
[ "python", "time", "count" ]
Get data from shown plot in matplotlib and pass it to a probability density function
37,641,557
<p>I have a plot in matplotlib created from an array of data. I have added a button labeled 'PD'. How do I get data from the plot and pass it to a probability density function when the button is clicked? I've tried going through the documentation but it's not that clear.</p>
1
2016-06-05T11:51:22Z
37,641,954
<p>You can try using the <code>gca</code> method in <code>matplotlib</code> to retrieve the data from an active plot.</p> <pre><code>import numpy as np import matplotlib.pyplot as plt x = np.linspace(0, 100, 100) y1 = x**2 plt.plot(x, y1) line = plt.gca().get_lines() x_data = lines[0].get_data()[0] y1_data = line...
2
2016-06-05T12:32:54Z
[ "python", "matplotlib", "plot" ]
How to get Sense Key in WordNet for NLTK Python?
37,641,584
<p>Hi Stackoverflow Community</p> <p>I just started tinkering around with Python NLTK and have directed my attention to the Wordnet module.</p> <p>I am attempting to get the Sense Ky for a given lemma and found the following:</p> <pre><code>s = wn.synset('skill.n.01') s.lemmas # &gt;&gt;&gt; [Lemma('skill.n.01.skill...
1
2016-06-05T11:54:48Z
37,644,061
<p>If you look at an example of this module, e.g. in <a href="http://www.nltk.org/howto/wordnet.html" rel="nofollow">http://www.nltk.org/howto/wordnet.html</a>, <code>lemmas</code> is a method - so you need to call it with () after it, for example:</p> <pre><code>s = wn.synset('skill.n.01') s.lemmas() # &gt;&gt;&gt; [...
1
2016-06-05T16:14:02Z
[ "python", "nlp", "nltk", "wordnet", "open-multilingual-wordnet" ]
How to get Sense Key in WordNet for NLTK Python?
37,641,584
<p>Hi Stackoverflow Community</p> <p>I just started tinkering around with Python NLTK and have directed my attention to the Wordnet module.</p> <p>I am attempting to get the Sense Ky for a given lemma and found the following:</p> <pre><code>s = wn.synset('skill.n.01') s.lemmas # &gt;&gt;&gt; [Lemma('skill.n.01.skill...
1
2016-06-05T11:54:48Z
37,658,487
<p>So I figured it out. After a bit of digging in NLTK's Wordnet API, I noticed that the API appears to require the key to be called like this:</p> <pre><code>s = wn.synset('skill.n.01') print(s.lemmas) # &gt;&gt;&gt; &lt;bound method Synset.lemmas of Synset('skill.n.01')&gt; print(str(s.lemmas()[0]._key)) #&gt;&gt;&...
0
2016-06-06T13:15:01Z
[ "python", "nlp", "nltk", "wordnet", "open-multilingual-wordnet" ]
How to get Sense Key in WordNet for NLTK Python?
37,641,584
<p>Hi Stackoverflow Community</p> <p>I just started tinkering around with Python NLTK and have directed my attention to the Wordnet module.</p> <p>I am attempting to get the Sense Ky for a given lemma and found the following:</p> <pre><code>s = wn.synset('skill.n.01') s.lemmas # &gt;&gt;&gt; [Lemma('skill.n.01.skill...
1
2016-06-05T11:54:48Z
37,788,609
<p>Take a look at <a href="http://stackoverflow.com/a/27518899/610569">http://stackoverflow.com/a/27518899/610569</a> for the difference between, <code>Synset.lemmas()[0].key</code> and <code>Synset.lemmas()[0].key()</code>:</p> <pre><code>&gt;&gt;&gt; from nltk.corpus import wordnet as wn &gt;&gt;&gt; wn.synset('dog....
1
2016-06-13T11:26:55Z
[ "python", "nlp", "nltk", "wordnet", "open-multilingual-wordnet" ]
iterating through hierarchical structures in Python
37,641,649
<p>I have a set of numbered groups in a data set that are organized hierarchically. Each group has a numbered title and has several members of that group. For example:</p> <pre><code>01 : Tony, John, Meredith 01.01 : Alex, Fred, Melissa 02 : Alley, Henry, Natalie 02.01.02 : Chris, Pete 03 : Andrew 03.01 : Nancy, Peter...
0
2016-06-05T12:02:26Z
37,641,768
<p>You ask "What data structure should I use in python to organize these groups?"</p> <p>A key principle of top-down programming is that you do not decide the implementation of an abstract data structure until you have decided the operations that will be done on the structure as well as their relative frequencies and ...
1
2016-06-05T12:14:47Z
[ "python", "data-structures", "hierarchy" ]
iterating through hierarchical structures in Python
37,641,649
<p>I have a set of numbered groups in a data set that are organized hierarchically. Each group has a numbered title and has several members of that group. For example:</p> <pre><code>01 : Tony, John, Meredith 01.01 : Alex, Fred, Melissa 02 : Alley, Henry, Natalie 02.01.02 : Chris, Pete 03 : Andrew 03.01 : Nancy, Peter...
0
2016-06-05T12:02:26Z
37,642,019
<p>If your main goal is to produce a JSON-friendly structure you can write out, use nested dictionaries (or <code>OrderedDict</code> if the order of elements is important). It keeps things simple, and writing it out with json will be trivial. Each dictionary can have a key <code>members</code> (a list or set of the chi...
0
2016-06-05T12:40:17Z
[ "python", "data-structures", "hierarchy" ]
multiple figures generated by python loop but drawn only after loop ends
37,641,799
<p>I have the following code which take a list of object, and for each object draws a figure from data stored in the object:</p> <pre><code>def Plot(self, *figures , wait = True): def plot(fig,n): fig.fig = plt.figure(n) print("Ploting figure {} for file {}\n".format(n,fig.name)) fig.Plot...
1
2016-06-05T12:18:06Z
37,671,463
<p>After some more googling i found a solution at : physicalmodelingwithpython.blogspot.co.il/2015/07/… where the line: "if wait: input("Press Enter to continue to next figure")" should be replaced with: "while True: if plt.waitforbuttonpress(): break"</p> <p>plt.waitforbuttonpress() returns True is a key is presses...
0
2016-06-07T05:50:23Z
[ "python", "loops", "matplotlib", "plot", "iteration" ]
Python module import works for one file, fails for another
37,642,004
<p>I'm facing a very strange problem. I've got three files, the first contains the base class, from which the classes in the other two files inherit from.</p> <p>The strange thing is, everything worked fine yesterday, but one of the files doesn't work anymore today. I haven't touched the imports in the meantime.</p> ...
2
2016-06-05T12:38:58Z
37,642,161
<p>It looks like your problem is a not-complete understanding of how python finds modules.</p> <p>For an <a href="https://www.python.org/dev/peps/pep-0328/" rel="nofollow">absolute import</a> (i.e. one where you specify the name of the first module such as <code>import mymodule</code>, and don't use a period to do a r...
1
2016-06-05T12:55:53Z
[ "python", "python-3.x" ]
Python module import works for one file, fails for another
37,642,004
<p>I'm facing a very strange problem. I've got three files, the first contains the base class, from which the classes in the other two files inherit from.</p> <p>The strange thing is, everything worked fine yesterday, but one of the files doesn't work anymore today. I haven't touched the imports in the meantime.</p> ...
2
2016-06-05T12:38:58Z
37,642,172
<p>Just a thought. Have you checked the permissions? Maybe somehow the permissions got messed up and they are giving you the problems.</p>
1
2016-06-05T12:56:53Z
[ "python", "python-3.x" ]
What is the point of storing values in a sequence of instances?
37,642,033
<p>The twitter API layer implementation for python (<a href="https://github.com/bear/python-twitter/blob/master/twitter/api.py" rel="nofollow">https://github.com/bear/python-twitter/blob/master/twitter/api.py</a>) at <a href="https://github.com/bear/python-twitter" rel="nofollow">A Python wrapper around the Twitter API...
0
2016-06-05T12:42:04Z
37,642,227
<p>The ultimate answer in this case can only be given by the authors of that implementation.</p> <p>In general deeply nesting information leads to generic solutions for producers of that information instance, but puts more strain on the consumer (especially a gerneic one) to sort things out as they have been meant.</p...
1
2016-06-05T13:03:32Z
[ "python", "class", "twitter", "flatten" ]
Left-most column not recognised when transposed - Yahoo finance pandas
37,642,193
<p>I'm very new to coding, but am really enjoying messing around with pulling data off Yahoo finance. I've so far come up with code that pulls the close price off for select tickers, and calculates the monthly % change - displaying it as a transposed table with 2 columns. When returning the data in a dataframe, I want ...
1
2016-06-05T13:00:01Z
37,644,724
<p>after executing your code i have the following:</p> <pre><code>In [317]: transposed.columns Out[317]: DatetimeIndex(['2016-06-03'], dtype='datetime64[ns]', name='Date', freq='B') In [318]: transposed.info() &lt;class 'pandas.core.frame.DataFrame'&gt; Index: 2 entries, AAPL to TSLA Data columns (total 1 columns): 2...
0
2016-06-05T17:23:48Z
[ "python", "pandas", "dataframe", "transpose", "yahoo-finance" ]
Can't parse tag from XML using Python
37,642,258
<p>I can't figure out how to get tag <code>Characters</code> from XML which is a part of <code>DOCX</code> file. The <code>DOCX</code> file contains multiple files including <code>app.xml</code>. I want to get tag or property <code>&lt;Characters&gt;</code> from this <code>XML</code>.</p> <p><a href="http://i.stack.im...
1
2016-06-05T13:06:50Z
37,642,490
<p>You can use etree module like this:</p> <pre><code>#to load the xml from lxml import etree doc=etree.parse("the path to your xml file") #to find the Characters tab doc.find("Characters").text </code></pre> <p>Of course if <code>Characters</code> wasn't a root node, you'd need to put the full path. Something like...
-1
2016-06-05T13:30:50Z
[ "python", "xml", "xpath", "lxml" ]
Can't parse tag from XML using Python
37,642,258
<p>I can't figure out how to get tag <code>Characters</code> from XML which is a part of <code>DOCX</code> file. The <code>DOCX</code> file contains multiple files including <code>app.xml</code>. I want to get tag or property <code>&lt;Characters&gt;</code> from this <code>XML</code>.</p> <p><a href="http://i.stack.im...
1
2016-06-05T13:06:50Z
37,642,520
<p>Problem in this case is in the xml declaration of the file. The attribute standalone may only contain the value yes or no. So lxml on my machine bails out during parsing stage ...</p> <p>When I use the following file:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt; &lt;Properties&gt; ...
0
2016-06-05T13:33:50Z
[ "python", "xml", "xpath", "lxml" ]
Can't parse tag from XML using Python
37,642,258
<p>I can't figure out how to get tag <code>Characters</code> from XML which is a part of <code>DOCX</code> file. The <code>DOCX</code> file contains multiple files including <code>app.xml</code>. I want to get tag or property <code>&lt;Characters&gt;</code> from this <code>XML</code>.</p> <p><a href="http://i.stack.im...
1
2016-06-05T13:06:50Z
37,642,723
<p>This is a frequently asked problem related to <em>default namespace</em>. Your XML has default namespace declared at the root element :</p> <pre><code>xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties}" </code></pre> <p>This means, all elements without prefix, including your target e...
1
2016-06-05T13:56:45Z
[ "python", "xml", "xpath", "lxml" ]
List of arrays: How to plot elements of each array(Python 2.7)?
37,642,282
<p>It's hard to describe the problem I'm facing.</p> <p>I have a list of arrays that looks like:</p> <p><code>['a', 'b', 'c', 'd', 'e'], ['a1', 'b1', 'c1', 'd1', 'e1']... etc</code></p> <p>I'd like to plot d vs e for each element.</p> <p>The way I'm trying (which I know is wrong, but I just don't know what the righ...
-1
2016-06-05T13:09:20Z
37,642,454
<p>You should use:</p> <pre><code>for i in list: pl.plot(i[3],i[4]) </code></pre> <p>instead of</p> <pre><code>for i in list: pl.plot(list[i][3],list[i][4]) </code></pre> <hr> <p><strong>Solution to your problem:</strong></p> <pre><code>from matplotlib import pyplot l=[[1,2,3,4,5],[10,11,12,13,14,15]] d=[]...
-1
2016-06-05T13:26:50Z
[ "python", "arrays", "list", "plot" ]
List of arrays: How to plot elements of each array(Python 2.7)?
37,642,282
<p>It's hard to describe the problem I'm facing.</p> <p>I have a list of arrays that looks like:</p> <p><code>['a', 'b', 'c', 'd', 'e'], ['a1', 'b1', 'c1', 'd1', 'e1']... etc</code></p> <p>I'd like to plot d vs e for each element.</p> <p>The way I'm trying (which I know is wrong, but I just don't know what the righ...
-1
2016-06-05T13:09:20Z
37,642,483
<p>If you have a list of lists like this:</p> <pre><code>lists = [['a', 'b', 'c', 'd', 'e'], ['a1', 'a2', 'a3', 'a4', 'a5'],..] </code></pre> <p>Then, if you iterate over it with a for loop, you'll get the individual lists as the items as the items. The third element is offset 2, and the fourth is 3 (python lists ar...
0
2016-06-05T13:29:43Z
[ "python", "arrays", "list", "plot" ]
List of arrays: How to plot elements of each array(Python 2.7)?
37,642,282
<p>It's hard to describe the problem I'm facing.</p> <p>I have a list of arrays that looks like:</p> <p><code>['a', 'b', 'c', 'd', 'e'], ['a1', 'b1', 'c1', 'd1', 'e1']... etc</code></p> <p>I'd like to plot d vs e for each element.</p> <p>The way I'm trying (which I know is wrong, but I just don't know what the righ...
-1
2016-06-05T13:09:20Z
37,642,628
<p>You can't plot 2 strings but you can plot their indexes like;</p> <pre><code>import matplotlib.pyplot as pl lst1 = [['a', 'b', 'c', 'd', 'e'],['a1', 'b1', 'c1', 'd1', 'e1'], ['a2', 'b2', 'c2', 'd2', 'e2'],['a3', 'b3', 'c3', 'd3', 'e3']] for x in lst1: pl.plot([3,4]) pl.xlabel("{}".format(x[3])) ...
0
2016-06-05T13:47:02Z
[ "python", "arrays", "list", "plot" ]
search for string in json file
37,642,379
<p>i have a dictionary which the user enters values in at the beginning, those values are then stored into a txt file in json format. The goal is for the user to be able to search the json file with a string of their choice. I have tried a variety of ways but have come up unsuccesful. The code below shows if the user e...
1
2016-06-05T13:19:13Z
37,642,853
<p>You could do it like this:</p> <pre><code>if choice == 'a': # Add a new joke. # See Point 3 of the "Requirements of admin.py" section of the assignment brief. jokeSetup = input('Enter setup of joke: ') jokePunchLine = input('Enter punchline of joke: ') entry = {'setup': jokeSetup , 'punchline': jokePunc...
1
2016-06-05T14:10:14Z
[ "python", "json", "list", "dictionary" ]
search for string in json file
37,642,379
<p>i have a dictionary which the user enters values in at the beginning, those values are then stored into a txt file in json format. The goal is for the user to be able to search the json file with a string of their choice. I have tried a variety of ways but have come up unsuccesful. The code below shows if the user e...
1
2016-06-05T13:19:13Z
37,643,804
<pre><code>import json import sys import os data = [] if os.stat("data.txt").st_size != 0 : file = open('data.txt', 'r') data = json.load(file) print(data) choice = input("What's your choice ?") if choice == 'a': # Add a new joke. # See Point 3 of the "Requirements of admin.py" section of the assig...
1
2016-06-05T15:49:42Z
[ "python", "json", "list", "dictionary" ]
Contig Extension - Search for smallest extension
37,642,401
<p>i want to write a function that extends contigs (overlapping dna sequences) into a large one. For that i need to find overlapping sequences from a dictionary consisting of those sequences as keys and values. I need to find the "smallest extension" to the right and left of the initial sequence but i couldn't come up ...
0
2016-06-05T13:22:08Z
37,680,343
<p>If you extends contigs by small reads, use 10, as here: <a href="http://sco.h-its.org/exelixis/web/software/pear/doc.html" rel="nofollow">http://sco.h-its.org/exelixis/web/software/pear/doc.html</a></p> <p>Else if you concatenate large contigs, maybe 10% of length may be useful? You may use threshold 10% and remove...
0
2016-06-07T13:08:28Z
[ "python", "algorithm", "biopython" ]
Python Webscrapping list manipulation
37,642,403
<p>Hey I am new to Python and I am writing a program that extracts data from a webpage. With this search line: </p> <pre><code>carTypeWeb = soup.find_all("span", {"class":"h3"}) </code></pre> <p>I get the following output: </p> <pre><code>&gt; [&lt;span class="h3"&gt;BMW 420d Gran Coupe M-Sportpaket DIEBSTAHLSCHADE...
0
2016-06-05T13:22:34Z
37,642,472
<p>If you only want every other line why not changed you code to:</p> <pre><code>carTypeWeb = soup.find_all("span", {"class":"h3 u-block"}) </code></pre>
0
2016-06-05T13:28:50Z
[ "python", "web-scraping" ]
Python Webscrapping list manipulation
37,642,403
<p>Hey I am new to Python and I am writing a program that extracts data from a webpage. With this search line: </p> <pre><code>carTypeWeb = soup.find_all("span", {"class":"h3"}) </code></pre> <p>I get the following output: </p> <pre><code>&gt; [&lt;span class="h3"&gt;BMW 420d Gran Coupe M-Sportpaket DIEBSTAHLSCHADE...
0
2016-06-05T13:22:34Z
37,649,386
<p>You could do something like this:</p> <pre><code># To read only alternate items of list starting from item 2 for i in range(1, len(carTypeWeb), 2): price = (carTypeWeb[i].text).split(' ')[0].replace('.','') </code></pre> <p>In the above code, <code>.text</code> extracts the content between <code>span</code> t...
-1
2016-06-06T04:04:06Z
[ "python", "web-scraping" ]
Tracking the progress of a function in another function
37,642,414
<p>I have a Python back end running Flask, and it is going to have a function (or a few functions chained together) which will run several AJAX calls and perform some database operations. </p> <p>This will take a while, so on the front end I'm looking to poll the server at regular intervals and update the UI as progre...
2
2016-06-05T13:23:33Z
37,648,713
<p>Use a database to store the status. If you use something like redis, you can even do it realtime with pub/sub and websockets.</p> <p>The module-scoped variable is a bad choice. It doesn't scale.</p> <p>If it is a long running task, consider using a task queue, like <a href="http://python-rq.org/" rel="nofollow"><c...
1
2016-06-06T02:15:33Z
[ "python", "http", "asynchronous", "flask" ]
Using python to fill in text boxes on websites, and clicking button to download
37,642,452
<p>If given a website like e.g. <a href="http://www.barchart.com/historicaldata.php" rel="nofollow">http://www.barchart.com/historicaldata.php</a>, is there a way to fill in the text box and then click the submit button to download the data?</p> <p>I'm use to using <code>urllib</code> to download entire pages, but can...
0
2016-06-05T13:26:43Z
37,642,689
<p>There are two paths I can think of:</p> <p><strong>Selenium</strong></p> <p>It's possible to directly simulate filling in data and clicking the button using a great library called Selenium Webdriver. <a href="https://seleniumhq.github.io/selenium/docs/api/py/api.html" rel="nofollow">https://seleniumhq.github.io/se...
1
2016-06-05T13:52:52Z
[ "python", "html", "urllib", "algorithmic-trading" ]
python module import error without sudo
37,642,462
<p>I am using Ubuntu 14.04 I have installed a module pymavlink using sudo pip install pymavlink now when i run a code like</p> <blockquote> <p>python code.py</p> </blockquote> <p>it says no module names as pymavlink but when i run it as </p> <blockquote> <p>sudo python code.py</p> </blockquote> <p>it works fin...
0
2016-06-05T13:27:48Z
37,642,876
<p>I found the solution for the problem, it had permission issues, normal user didn't had the permission to execute the command, hence i added it by running the command</p> <blockquote> <p>sudo chmod 775 python2.7</p> </blockquote> <p>and same inside for its sub folders as well.</p> <blockquote> <p>sudo chmod 77...
0
2016-06-05T14:13:02Z
[ "python", "python-2.7" ]
Jupyter Notebook uses my system's python3.4 instead of anaconda's python3.5 as a kernel
37,642,502
<p>I had anaconda2 installed, and manually added the python3 kernel, so I could chose between python2 and python3. The problem was that I added my system's python3 binary, not anaconda's, so I was missing all the libraries that anaconda brings. Specifically I couldnt import 'from scipy.misc import imread'.</p> <p>So I...
0
2016-06-05T13:31:41Z
37,645,847
<p>Ended up solving it with:</p> <p>pip install -U ipython</p> <p>ipython3 kernelspec install-self</p>
0
2016-06-05T19:22:09Z
[ "python", "ipython", "jupyter" ]
Given a string, best way in Python to extract all integers in the string
37,642,563
<p>Given a string in unknown format, but expected to contain a known number of integers, I would like to extract those integers as a <code>List</code> or return an error if the number of integers does not match what is expected.</p> <p>So for example, if the string reads <code>'This is a test 1 2 3 55'</code>, and the...
-2
2016-06-05T13:40:11Z
37,642,692
<p>You can use a regular expression -</p> <pre><code>import re s = 'This is a test 1 2 3 55' expr = r'\d+' print(list(map(int, re.findall(expr, s)))) </code></pre> <p>If you don't want to use regex, this would also work -</p> <pre><code>s = 'This is a test 1 2 3 55' arr = [int(x) for x in s.split() if x.isdigit(...
6
2016-06-05T13:53:23Z
[ "python", "regex", "text" ]
Given a string, best way in Python to extract all integers in the string
37,642,563
<p>Given a string in unknown format, but expected to contain a known number of integers, I would like to extract those integers as a <code>List</code> or return an error if the number of integers does not match what is expected.</p> <p>So for example, if the string reads <code>'This is a test 1 2 3 55'</code>, and the...
-2
2016-06-05T13:40:11Z
37,643,045
<p>I would use a filter in order to get integers. We are searching for integers in the splitted string (which is a list).</p> <pre><code>In [55]: s = 'This is a test 1 2 3 55' In [56]: list(filter(lambda x: x.isdigit(), s.split())) Out[56]: ['1', '2', '3', '55'] </code></pre>
1
2016-06-05T14:32:10Z
[ "python", "regex", "text" ]
Given a string, best way in Python to extract all integers in the string
37,642,563
<p>Given a string in unknown format, but expected to contain a known number of integers, I would like to extract those integers as a <code>List</code> or return an error if the number of integers does not match what is expected.</p> <p>So for example, if the string reads <code>'This is a test 1 2 3 55'</code>, and the...
-2
2016-06-05T13:40:11Z
37,645,009
<p>As this is a pretty simple, split by space is better than using regex.</p> <p>Below is a program which can be up to your requirement. If you change the expected count from 4 to any other number, it will throw error as you specified.</p> <pre><code> strdata='This is a test 1 2 3 55' num=[] expected_count=4 for i...
0
2016-06-05T17:52:37Z
[ "python", "regex", "text" ]
Two images beneath each other QGridLayout PyQt
37,642,568
<p>I want to use a QGridLayout to structure my GUI. There need to be two images on top of each other, and I can only get the top one visible. I've made two QLabels, resized them to the proper size and set the QPixmap to the QLabel. After this I have set the labels at positions (1,1) and (2,1) however only the top one s...
-1
2016-06-05T13:40:30Z
37,642,659
<p>I'm an idiot, I added the wrong widget to the layout. Last line should have been:</p> <pre><code>identifyLayout.addWidget(frontMatchImg, 2, 1) </code></pre> <p>Plus the resizes are not necessary and the indexing starts at 0.</p>
0
2016-06-05T13:49:59Z
[ "python", "pyqt", "pyqt4" ]
How can I make sense of the `else` statement in Python loops?
37,642,573
<p>Many Python programmers are probably unaware that the syntax of <code>while</code> loops and <code>for</code> loops includes an optional <code>else:</code> clause:</p> <pre><code>for val in iterable: do_something(val) else: clean_up() </code></pre> <p>The body of the <code>else</code> clause is a good plac...
173
2016-06-05T13:41:04Z
37,643,193
<p>When does an <code>if</code> execute an <code>else</code>? When its condition is false. It is exactly the same for the <code>while</code>/<code>else</code>. So you can think of <code>while</code>/<code>else</code> as just an <code>if</code> that keeps running its true condition until it evaluates false. A <code>br...
29
2016-06-05T14:46:51Z
[ "python", "loops", "for-loop", "while-loop" ]
How can I make sense of the `else` statement in Python loops?
37,642,573
<p>Many Python programmers are probably unaware that the syntax of <code>while</code> loops and <code>for</code> loops includes an optional <code>else:</code> clause:</p> <pre><code>for val in iterable: do_something(val) else: clean_up() </code></pre> <p>The body of the <code>else</code> clause is a good plac...
173
2016-06-05T13:41:04Z
37,643,265
<p>This is what it essentially means:</p> <pre><code>for/while ...: if ...: break if there was a break: pass else: ... </code></pre> <p>It's a nicer way of writing of this common pattern:</p> <pre><code>found = False for/while ...: if ...: found = True break if not found: ...
20
2016-06-05T14:53:43Z
[ "python", "loops", "for-loop", "while-loop" ]
How can I make sense of the `else` statement in Python loops?
37,642,573
<p>Many Python programmers are probably unaware that the syntax of <code>while</code> loops and <code>for</code> loops includes an optional <code>else:</code> clause:</p> <pre><code>for val in iterable: do_something(val) else: clean_up() </code></pre> <p>The body of the <code>else</code> clause is a good plac...
173
2016-06-05T13:41:04Z
37,643,296
<p>If you think of your loops as a structure similar to this (somewhat pseudo-code):</p> <pre><code>loop: if condition then ... //execute body goto loop else ... </code></pre> <p>it might make a little bit more sense. A loop is essentially just an <code>if</code> statement that is repeated until the conditi...
19
2016-06-05T14:57:15Z
[ "python", "loops", "for-loop", "while-loop" ]
How can I make sense of the `else` statement in Python loops?
37,642,573
<p>Many Python programmers are probably unaware that the syntax of <code>while</code> loops and <code>for</code> loops includes an optional <code>else:</code> clause:</p> <pre><code>for val in iterable: do_something(val) else: clean_up() </code></pre> <p>The body of the <code>else</code> clause is a good plac...
173
2016-06-05T13:41:04Z
37,643,358
<p>Better to think of it this way: The <code>else</code> block will <strong>always</strong> be executed if everything goes <em>right</em> in the preceding <code>for</code> block such that it reaches exhaustion. </p> <p><em>Right</em> in this context will mean no <code>exception</code>, no <code>break</code>, no <code>...
31
2016-06-05T15:02:49Z
[ "python", "loops", "for-loop", "while-loop" ]
How can I make sense of the `else` statement in Python loops?
37,642,573
<p>Many Python programmers are probably unaware that the syntax of <code>while</code> loops and <code>for</code> loops includes an optional <code>else:</code> clause:</p> <pre><code>for val in iterable: do_something(val) else: clean_up() </code></pre> <p>The body of the <code>else</code> clause is a good plac...
173
2016-06-05T13:41:04Z
37,643,965
<p>Usually I tend to think of a loop structure like this:</p> <pre><code>for item in my_sequence: if logic(item): do_something(item) break </code></pre> <p>To be a lot like a variable number of <code>if/elif</code> statements:</p> <pre><code>if logic(my_seq[0]): do_something(my_seq[0]) elif l...
5
2016-06-05T16:05:52Z
[ "python", "loops", "for-loop", "while-loop" ]
How can I make sense of the `else` statement in Python loops?
37,642,573
<p>Many Python programmers are probably unaware that the syntax of <code>while</code> loops and <code>for</code> loops includes an optional <code>else:</code> clause:</p> <pre><code>for val in iterable: do_something(val) else: clean_up() </code></pre> <p>The body of the <code>else</code> clause is a good plac...
173
2016-06-05T13:41:04Z
37,644,460
<p>(This is inspired by @Mark Tolonen's answer.)</p> <p>An <code>if</code> statement runs its <code>else</code> clause if its condition evaluates to false. Identically, a <code>while</code> loop runs the else clause if its condition evaluates to false.</p> <p>This rule matches the behavior you described:</p> <ul> <l...
192
2016-06-05T16:54:53Z
[ "python", "loops", "for-loop", "while-loop" ]
How can I make sense of the `else` statement in Python loops?
37,642,573
<p>Many Python programmers are probably unaware that the syntax of <code>while</code> loops and <code>for</code> loops includes an optional <code>else:</code> clause:</p> <pre><code>for val in iterable: do_something(val) else: clean_up() </code></pre> <p>The body of the <code>else</code> clause is a good plac...
173
2016-06-05T13:41:04Z
37,648,033
<p>Think of the <code>else</code> clause as being part of the loop construct; <code>break</code> breaks out of the loop construct entirely, and thus skips the <code>else</code> clause.</p> <p>But really, my mental mapping is simply that it's the 'structured' version of the pattern C/C++ pattern:</p> <pre><code> for ...
3
2016-06-06T00:13:11Z
[ "python", "loops", "for-loop", "while-loop" ]
How can I make sense of the `else` statement in Python loops?
37,642,573
<p>Many Python programmers are probably unaware that the syntax of <code>while</code> loops and <code>for</code> loops includes an optional <code>else:</code> clause:</p> <pre><code>for val in iterable: do_something(val) else: clean_up() </code></pre> <p>The body of the <code>else</code> clause is a good plac...
173
2016-06-05T13:41:04Z
37,650,949
<p>Others have already explained the mechanics of <code>while/for...else</code>, and the <a href="https://docs.python.org/3/reference/">Python 3 language reference</a> has the authoritative definition (see <a href="https://docs.python.org/3/reference/compound_stmts.html#the-while-statement">while</a> and <a href="https...
5
2016-06-06T06:37:43Z
[ "python", "loops", "for-loop", "while-loop" ]
How can I make sense of the `else` statement in Python loops?
37,642,573
<p>Many Python programmers are probably unaware that the syntax of <code>while</code> loops and <code>for</code> loops includes an optional <code>else:</code> clause:</p> <pre><code>for val in iterable: do_something(val) else: clean_up() </code></pre> <p>The body of the <code>else</code> clause is a good plac...
173
2016-06-05T13:41:04Z
37,658,079
<p>My gotcha moment with the loop's <code>else</code> clause was when I was watching a talk by <a href="http://stackoverflow.com/users/1001643/raymond-hettinger">Raymond Hettinger</a>, who told a story about how he thought it should have been called <code>nobreak</code>. Take a look at the following code, what do you t...
13
2016-06-06T12:54:57Z
[ "python", "loops", "for-loop", "while-loop" ]
How can I make sense of the `else` statement in Python loops?
37,642,573
<p>Many Python programmers are probably unaware that the syntax of <code>while</code> loops and <code>for</code> loops includes an optional <code>else:</code> clause:</p> <pre><code>for val in iterable: do_something(val) else: clean_up() </code></pre> <p>The body of the <code>else</code> clause is a good plac...
173
2016-06-05T13:41:04Z
37,662,589
<p>In <a href="http://en.wikipedia.org/wiki/Test-driven_development" rel="nofollow">Test-driven development</a> (TDD), when using the <a href="https://en.wikipedia.org/wiki/Transformation_Priority_Premise" rel="nofollow">Transformation Priority Premise</a> paradigm, you treat loops as a generalization of conditional st...
6
2016-06-06T16:34:18Z
[ "python", "loops", "for-loop", "while-loop" ]
How can I make sense of the `else` statement in Python loops?
37,642,573
<p>Many Python programmers are probably unaware that the syntax of <code>while</code> loops and <code>for</code> loops includes an optional <code>else:</code> clause:</p> <pre><code>for val in iterable: do_something(val) else: clean_up() </code></pre> <p>The body of the <code>else</code> clause is a good plac...
173
2016-06-05T13:41:04Z
37,664,133
<p>Decision structures evaluate multiple expressions which produce TRUE or FALSE as outcome. You need to determine which action to take and which statements to execute if outcome is TRUE or FALSE otherwise.</p> <blockquote> <p>Basically, without if Statement ,else Statement Does not mean.!</p> </blockquote> <pre><c...
-3
2016-06-06T18:11:21Z
[ "python", "loops", "for-loop", "while-loop" ]
How can I make sense of the `else` statement in Python loops?
37,642,573
<p>Many Python programmers are probably unaware that the syntax of <code>while</code> loops and <code>for</code> loops includes an optional <code>else:</code> clause:</p> <pre><code>for val in iterable: do_something(val) else: clean_up() </code></pre> <p>The body of the <code>else</code> clause is a good plac...
173
2016-06-05T13:41:04Z
37,670,045
<p>The way I see it, <code>else:</code> fires when you iterate past the end of the loop.</p> <p>If you <code>break</code> or <code>return</code> or <code>raise</code> you don't iterate past the end of loop, you stop immeadiately, and thus the <code>else:</code> block won't run. If you <code>continue</code> you still i...
5
2016-06-07T03:34:25Z
[ "python", "loops", "for-loop", "while-loop" ]
How can I make sense of the `else` statement in Python loops?
37,642,573
<p>Many Python programmers are probably unaware that the syntax of <code>while</code> loops and <code>for</code> loops includes an optional <code>else:</code> clause:</p> <pre><code>for val in iterable: do_something(val) else: clean_up() </code></pre> <p>The body of the <code>else</code> clause is a good plac...
173
2016-06-05T13:41:04Z
37,704,287
<p>The way I think about it, the key is to consider the meaning of <code>continue</code> rather than <code>else</code>.</p> <p>The other keywords you mention break out of the loop (exit abnormally) whilst <code>continue</code> does not, it just skips the remainder of the code block inside the loop. The fact that it ca...
1
2016-06-08T13:43:59Z
[ "python", "loops", "for-loop", "while-loop" ]
Appending two items in one list to a new list in Python
37,642,579
<p>I have a list that currently looks like:</p> <pre><code>new_list = ['130 kms', '46 kms', '169 kms', '179 kms', '53 kms', '128 kms', '97 kms', '152 kms', '20 kms', '94 kms', '$266.07', '$174.14', '$187.01', '$488.69', '$401.53', '$106.88', '$398.33', '$493.87', '$205.43', '$248.14'] </code></pre> <p>The first eleme...
1
2016-06-05T13:41:46Z
37,642,621
<p>You can use list comprehension to create the nested lists. This does the trick: </p> <pre><code>result = [] for i in range(len(new_list)/2): result.append([new_list[i],new_list[i+10]) </code></pre> <p>Note that if you had a different input string length, you should change the last line to:</p> <pre><code>r...
1
2016-06-05T13:45:46Z
[ "python", "list" ]
Appending two items in one list to a new list in Python
37,642,579
<p>I have a list that currently looks like:</p> <pre><code>new_list = ['130 kms', '46 kms', '169 kms', '179 kms', '53 kms', '128 kms', '97 kms', '152 kms', '20 kms', '94 kms', '$266.07', '$174.14', '$187.01', '$488.69', '$401.53', '$106.88', '$398.33', '$493.87', '$205.43', '$248.14'] </code></pre> <p>The first eleme...
1
2016-06-05T13:41:46Z
37,642,672
<p>Split your list as follows:</p> <pre><code>a = ['130 kms', '46 kms', '169 kms', '179 kms', '53 kms', '128 kms', '97 kms', '152 kms', '20 kms', '94 kms'] b = ['$266.07', '$174.14', '$187.01', '$488.69', '$401.53', '$106.88', '$398.33', '$493.87', '$205.43', '$248.14'] </code></pre> <p>then do zip(a, b), which retu...
0
2016-06-05T13:51:14Z
[ "python", "list" ]
Appending two items in one list to a new list in Python
37,642,579
<p>I have a list that currently looks like:</p> <pre><code>new_list = ['130 kms', '46 kms', '169 kms', '179 kms', '53 kms', '128 kms', '97 kms', '152 kms', '20 kms', '94 kms', '$266.07', '$174.14', '$187.01', '$488.69', '$401.53', '$106.88', '$398.33', '$493.87', '$205.43', '$248.14'] </code></pre> <p>The first eleme...
1
2016-06-05T13:41:46Z
37,642,674
<p>Your code is breaking, as explained by the error, because you're looping through a list of strings, and then using that string as the list index, which isn't allowed.</p> <p>If I understood your objective correctly, you want the result to be a list of lists such as:</p> <pre><code>&gt;&gt; [['130 kms', '$266.07'],...
1
2016-06-05T13:51:24Z
[ "python", "list" ]
Appending two items in one list to a new list in Python
37,642,579
<p>I have a list that currently looks like:</p> <pre><code>new_list = ['130 kms', '46 kms', '169 kms', '179 kms', '53 kms', '128 kms', '97 kms', '152 kms', '20 kms', '94 kms', '$266.07', '$174.14', '$187.01', '$488.69', '$401.53', '$106.88', '$398.33', '$493.87', '$205.43', '$248.14'] </code></pre> <p>The first eleme...
1
2016-06-05T13:41:46Z
37,642,693
<pre><code>new_list = ['130 kms', '46 kms', '169 kms', '179 kms', '53 kms', '128 kms', '97 kms', '152 kms', '20 kms', '94 kms', '$266.07', '$174.14', '$187.01', '$488.69', '$401.53', '$106.88', '$398.33', '$493.87', '$205.43', '$248.14'] new_list1 = [] for x in new_list: try: new_list1.append([x,new_list[...
0
2016-06-05T13:53:30Z
[ "python", "list" ]
Appending two items in one list to a new list in Python
37,642,579
<p>I have a list that currently looks like:</p> <pre><code>new_list = ['130 kms', '46 kms', '169 kms', '179 kms', '53 kms', '128 kms', '97 kms', '152 kms', '20 kms', '94 kms', '$266.07', '$174.14', '$187.01', '$488.69', '$401.53', '$106.88', '$398.33', '$493.87', '$205.43', '$248.14'] </code></pre> <p>The first eleme...
1
2016-06-05T13:41:46Z
37,642,857
<p>This might be a classic XY problem. I wonder why you would not back up a bit and collect the data in the form you need for this step. However, I will post an answer because I think one problem with the existing is that you have to know the number and position of each item in the list. </p> <p>My solution does no...
0
2016-06-05T14:10:35Z
[ "python", "list" ]
Appending two items in one list to a new list in Python
37,642,579
<p>I have a list that currently looks like:</p> <pre><code>new_list = ['130 kms', '46 kms', '169 kms', '179 kms', '53 kms', '128 kms', '97 kms', '152 kms', '20 kms', '94 kms', '$266.07', '$174.14', '$187.01', '$488.69', '$401.53', '$106.88', '$398.33', '$493.87', '$205.43', '$248.14'] </code></pre> <p>The first eleme...
1
2016-06-05T13:41:46Z
37,643,247
<p>Here is it: Easy with a list comprehension</p> <p>NewList1 = [[value, new_list[index]] for (index, value) in enumerate(new_list[:11], 11)]</p>
0
2016-06-05T14:52:01Z
[ "python", "list" ]
GoogleScraper on Windows - Error setup.py egg_info
37,642,617
<p>I have a problem for install GoogleScraper with python. I am lost. Look my problem : <a href="http://i.stack.imgur.com/L7JkT.jpg" rel="nofollow">Capture</a></p> <pre class="lang-sh prettyprint-override"><code> File "C:\Python34\lib\distutils\command\build_py.py", line 55, in finalize_options self.package_dir[n...
-1
2016-06-05T13:45:35Z
37,643,808
<p>I solved my problem with this solution --> <a href="https://github.com/NikolaiT/GoogleScraper/pull/150/commits/1158b5fe2b9af30e312773cc8d71060c6a134d46" rel="nofollow">Github</a></p> <p>I had removed a slash in the file "setup.py" for correctly install GoogleScraper.</p> <p>Go at line 24 for the changing.</p> <pr...
0
2016-06-05T15:50:13Z
[ "python", "windows", "pip" ]
Creating a dictionary whose keys give multiplicities of the values occurring in an array of an array
37,642,662
<p>I have this: </p> <pre><code>array1 = [[1,2,3],[1,2,3],[2,1,3],[2,1,3],[1,-2,3]] array2 = [[1,2,3],[1,2,3],[1,2,3],[1,2,3],[0,2,3],[2,1,3]] </code></pre> <p>and want to create this: </p> <pre><code>multiArray1 = {[1,2,3]:2, [2,1,3]:2} multiArray2 = {[1,2,3]:4, [2,1,3]:1} </code></pre> <p>Question: I am trying to...
0
2016-06-05T13:50:07Z
37,642,756
<p>The trick is, convert them to a string before you make them a key of a dict, because you can not have list as key for a dictionary.</p> <pre><code>dct1 = {} dct2 = {} array1 = [[1,2,3],[1,2,3],[2,1,3],[2,1,3],[1,-2,3]] array2 = [[1,2,3],[1,2,3],[1,2,3],[1,2,3],[0,2,3],[2,1,3]] for x in array1: cnt = array1.cou...
0
2016-06-05T13:59:19Z
[ "python", "arrays", "python-3.x", "dictionary", "multiplicity" ]
Creating a dictionary whose keys give multiplicities of the values occurring in an array of an array
37,642,662
<p>I have this: </p> <pre><code>array1 = [[1,2,3],[1,2,3],[2,1,3],[2,1,3],[1,-2,3]] array2 = [[1,2,3],[1,2,3],[1,2,3],[1,2,3],[0,2,3],[2,1,3]] </code></pre> <p>and want to create this: </p> <pre><code>multiArray1 = {[1,2,3]:2, [2,1,3]:2} multiArray2 = {[1,2,3]:4, [2,1,3]:1} </code></pre> <p>Question: I am trying to...
0
2016-06-05T13:50:07Z
37,642,814
<p>As someone noted, you can't use lists. In my approach, you need to convert your sublists to tuples and then update a dictionary.</p> <pre><code>In [48]: array1 = [[1,2,3],[1,2,3],[2,1,3],[2,1,3],[1,-2,3]] In [49]: array1 = list(map(lambda x: tuple(x), array1)) In [50]: array1 Out[50]: [(1, 2, 3), (1, 2, 3), (2, 1...
1
2016-06-05T14:05:30Z
[ "python", "arrays", "python-3.x", "dictionary", "multiplicity" ]
The Label Isn't Upadting
37,642,779
<pre><code>def timer(self, delay, counter): while self.exitPro == False: while self.isOn: time.sleep(delay) counter += 1 self.timed = counter print(self.timed) </code></pre> <p>Def Timer Is A Thread that is constantly running in the ba...
-1
2016-06-05T14:01:46Z
37,643,264
<p>Use <code>after</code>:</p> <pre><code>def main(self): [...] self.stopwatch_value = IntVar() stopwatch = ttk.Label(root, textvariable=self.stopwatch_value) stopwatch.grid(row=1, column=2) root.after(self.update, 500) def update(self): self.stopwatch_value.set(self.timed) root.after(self...
0
2016-06-05T14:53:22Z
[ "python", "multithreading", "python-3.x" ]
KeyError on python script
37,642,858
<p>I have this script to delete files from my slack account:</p> <pre><code>import requests import json import calendar import re from datetime import datetime, timedelta _token = re.escape("token") _domain = re.escape("domain") if __name__ == '__main__': while 1: files_list_url = 'https://slack.com/api/...
0
2016-06-05T14:10:40Z
37,642,908
<p>Switch</p> <pre><code>if len(response.json()["files"]) == 0: </code></pre> <p>To</p> <pre><code>if len(response.json().get("files", [])) == 0: </code></pre> <p>By default, the get method returns <code>None</code> if the attribute doesn't exist, whereas the [] notation throws up an error if the item doesn't exist...
0
2016-06-05T14:16:13Z
[ "python", "json", "api" ]
KeyError on python script
37,642,858
<p>I have this script to delete files from my slack account:</p> <pre><code>import requests import json import calendar import re from datetime import datetime, timedelta _token = re.escape("token") _domain = re.escape("domain") if __name__ == '__main__': while 1: files_list_url = 'https://slack.com/api/...
0
2016-06-05T14:10:40Z
37,642,915
<p>You're expecting that <code>json.loads()</code> will return a dict that will have a key named <code>files</code>. But in reality, the parsed data doesn't have that key. </p> <p>You can do these instead: </p> <pre><code>payload = json.loads(content) files = payload.get('files') </code></pre> <p>This way <code>file...
0
2016-06-05T14:16:48Z
[ "python", "json", "api" ]
Am I using LMDB incorrectly? It says environment mapsize limit reached after 0 insertions
37,642,885
<p>I am trying to create an LMDB database for my Caffe machine learning project. But LMDB throws an error ont the first attempt to insert a data point, saying the environment mapsize is full.</p> <p>Here's the code that attempts to populate the database:</p> <pre><code>import numpy as np from PIL import Image import ...
0
2016-06-05T14:14:00Z
37,642,917
<p>map size is the maximum size of the whole DB, including metadata - it appears you used the number of expected records.</p> <p>you increase this number</p>
2
2016-06-05T14:17:25Z
[ "python", "database", "machine-learning", "lmdb" ]
Extracting data from 2 data frames and creating new one python
37,642,946
<p>Firstly I have 2 data frames one in which i have name of a guy and pages liked by him in columns. So no. of columns will be different for different person here is the example. 1st column is the name of user.Then pages liked by him is stored across the row.So no. of columns for 'random guy' will be different from 'ma...
-1
2016-06-05T14:21:19Z
37,644,489
<p>Consider melting your original two data frames then merge with latter two with aggregation on tags. Additionally, a final aggregation on tags to combine both pages and categories datasets. Do note: results do not match exactly with your desired results.</p> <pre><code>import pandas as pd import numpy as np ... ...
0
2016-06-05T16:57:59Z
[ "python", "python-2.7", "pandas" ]
Change color and size according to label (matplolib, python 3)
37,642,954
<p>I am trying to show a scatter plot using matplotlib and so far showing the data, color and size is good when hardcoded but what I need to assign size and color according to a label set, for example, DataSet looks like:</p> <pre><code>data = [[1,1],[1,1],[1,1]] label =['label1','label3','label3'] </code></pre> <p>T...
1
2016-06-05T14:21:55Z
37,644,457
<p>Here's a snippet you can use. This <a href="http://matplotlib.org/examples/shapes_and_collections/scatter_demo.html" rel="nofollow">example from the matplotlib</a> docs might help if you need more customization.</p> <pre><code>import matplotlib.pyplot as plt data = [[1,2],[2,1],[1,1]] labels = ['label1','label2','...
2
2016-06-05T16:54:15Z
[ "python", "python-3.x", "matplotlib", "scatter-plot" ]
How to connect row values of a matrix with an index for a parameter
37,642,966
<p>I want to create a tables for a parameter ( lets say <code>X_n</code> for products from 1 to 3).<br> There are certain values that the parameter can take with a given probability value. </p> <p>Considering <code>n = 1</code> I can simulate the values that <code>X_1</code> can take with the following code</p> <pre>...
0
2016-06-05T14:23:34Z
37,644,318
<p>I'm not sure what you want to <em>do</em> with it so this is just printing out the result for each one</p> <pre><code>import numpy as np from scipy.stats import rv_discrete Xvalues = np.array([(-2,0,2), (0,2,3),(-2,0,2)]) Xprobabilities = np.array([(0.4,0.2,0.4), (0.2,0.4,0.4),(0.4,0.4,0.2)]) for values,probabili...
0
2016-06-05T16:40:03Z
[ "python", "numpy", "matrix", "simulation" ]
Python: How do I go through multiple lines in a file at once?
37,642,995
<p>I have created a class which loops through a file and after checking if a line is valid, it'll write that line to another file. Every line it checks is a lengthy process making it very slow. I need to implement either threading/multiprocessing at the process_file function; I do not know which library is best suited ...
2
2016-06-05T14:26:03Z
37,643,103
<blockquote> <p>The code goes through a proxy list checking whether it is online</p> </blockquote> <p>It sounds like what takes a long time is connecting to the internet, meaning your task is IO bound and thus threads can help speed it up. Multiple processes are always applicable but can be harder to use.</p>
1
2016-06-05T14:38:47Z
[ "python", "multithreading", "multiprocessing" ]
Python: How do I go through multiple lines in a file at once?
37,642,995
<p>I have created a class which loops through a file and after checking if a line is valid, it'll write that line to another file. Every line it checks is a lengthy process making it very slow. I need to implement either threading/multiprocessing at the process_file function; I do not know which library is best suited ...
2
2016-06-05T14:26:03Z
37,868,323
<p>If you are using the proxies, and want to test the proxies before using them, I would just use Proxicity (<a href="https://www.proxicity.io/api" rel="nofollow">https://www.proxicity.io/api</a>). They provide a free API of proxies that they check to make sure are up. It would make your code a lot lighter and less com...
0
2016-06-16T19:56:25Z
[ "python", "multithreading", "multiprocessing" ]
Python: How do I go through multiple lines in a file at once?
37,642,995
<p>I have created a class which loops through a file and after checking if a line is valid, it'll write that line to another file. Every line it checks is a lengthy process making it very slow. I need to implement either threading/multiprocessing at the process_file function; I do not know which library is best suited ...
2
2016-06-05T14:26:03Z
37,870,645
<p>This seems like a job for <code>multiprocessing.map</code>.</p> <pre><code>import multiprocessing def process_file(filename): pool = multiprocessing.Pool(4) with open(filename) as fd: results = pool.imap_unordered(do_stuff, (line for line in fd)) with open("output.txt", "w") as fd: ...
0
2016-06-16T22:53:34Z
[ "python", "multithreading", "multiprocessing" ]
Splitting one dictionary item into 2 variables
37,643,028
<p>I am trying to figure out how to split one dictionary value into 2 separate variables. For example the data I am trying to split is "Example":{"type":"Point","points":[14.670275,121.043955]}. I know that if I wanted the points as a whole it would look like:</p> <pre><code>VariA = tDict['Example']['points'] </code><...
0
2016-06-05T14:29:28Z
37,643,043
<pre><code>x, y = tDict['Example']['points'] </code></pre> <p>It's called tuple unpacking. If you also want <code>VariA</code> you can do:</p> <pre><code>x, y = VariA = tDict... </code></pre>
0
2016-06-05T14:32:06Z
[ "python", "dictionary", "sqlite3" ]
Splitting one dictionary item into 2 variables
37,643,028
<p>I am trying to figure out how to split one dictionary value into 2 separate variables. For example the data I am trying to split is "Example":{"type":"Point","points":[14.670275,121.043955]}. I know that if I wanted the points as a whole it would look like:</p> <pre><code>VariA = tDict['Example']['points'] </code><...
0
2016-06-05T14:29:28Z
37,643,047
<p><code>tDict['Example']['points']</code> is just a list, so:</p> <pre><code>p1 = tDict['Example']['points'][0] p2 = tDict['Example']['points'][1] </code></pre> <p>Or if you are unkeen about accessing the dictionary twice (not that it matters..):</p> <pre><code>points = tDict['Example']['points'] p1 = points[0] p2 ...
0
2016-06-05T14:32:30Z
[ "python", "dictionary", "sqlite3" ]
python average test score
37,643,044
<p>Im trying to write a program that will determine the average of a number tests. The number of tests will vary, but I do not want it to be initially set by user input. I'm want to use a while loop and a sentinel value of zero to stop the input. I would like the average to display to three decimal places, with the % s...
0
2016-06-05T14:32:07Z
37,643,066
<p><code>While</code> needs to be all lowercase.</p> <p><code>if entry == 0</code> is missing a colon.</p> <p><code>total += entry</code> and <code>counter += 1</code> need to be inside the loop since they must happen with every iteration.</p> <p>Did you try running the code you had before posting here?</p>
1
2016-06-05T14:35:00Z
[ "python", "while-loop", "average" ]
python average test score
37,643,044
<p>Im trying to write a program that will determine the average of a number tests. The number of tests will vary, but I do not want it to be initially set by user input. I'm want to use a while loop and a sentinel value of zero to stop the input. I would like the average to display to three decimal places, with the % s...
0
2016-06-05T14:32:07Z
37,643,116
<p>I see at least these two options: 1. store the values in an array and then, after the loop, calculate the average. 2. compute the average iteratively on each loop</p> <p>If you are expecting a significant number of inputs I would go for option (2).</p> <p>Regarding the formatting, this may be helpful: <a href="htt...
0
2016-06-05T14:39:41Z
[ "python", "while-loop", "average" ]
python average test score
37,643,044
<p>Im trying to write a program that will determine the average of a number tests. The number of tests will vary, but I do not want it to be initially set by user input. I'm want to use a while loop and a sentinel value of zero to stop the input. I would like the average to display to three decimal places, with the % s...
0
2016-06-05T14:32:07Z
37,643,129
<p>It doesn't look like you even tried, because your code as is in not able to run at all. However, here is the answer. You'll want to store the results in a list, then get the average by the sum of the list over the length of the list (number of scores). the .format method allows you to specify 3 decimal places.</p>...
0
2016-06-05T14:40:56Z
[ "python", "while-loop", "average" ]
python average test score
37,643,044
<p>Im trying to write a program that will determine the average of a number tests. The number of tests will vary, but I do not want it to be initially set by user input. I'm want to use a while loop and a sentinel value of zero to stop the input. I would like the average to display to three decimal places, with the % s...
0
2016-06-05T14:32:07Z
37,643,191
<p>The following should work.</p> <pre><code>scores = [] while True: entry = input("Enter test score: ") if entry == '': break elif not entry.isnumeric(): print("Scores must be numeric.") else: scores.append(int(entry)) average = sum(scores)/len(scores) print("The average score...
0
2016-06-05T14:46:38Z
[ "python", "while-loop", "average" ]
python average test score
37,643,044
<p>Im trying to write a program that will determine the average of a number tests. The number of tests will vary, but I do not want it to be initially set by user input. I'm want to use a while loop and a sentinel value of zero to stop the input. I would like the average to display to three decimal places, with the % s...
0
2016-06-05T14:32:07Z
37,643,491
<pre><code>total = 0 counter = 0 while True: entry = int(input("Enter Test score: ")) if entry == 0: break total += entry # this should be in while loop counter += 1 total = total * 1.0 if counter == 0: exit(1) avg = total / counter print("Average is: %3.f" % avg + '%') </code></pre> <p>total += en...
0
2016-06-05T15:20:17Z
[ "python", "while-loop", "average" ]
python average test score
37,643,044
<p>Im trying to write a program that will determine the average of a number tests. The number of tests will vary, but I do not want it to be initially set by user input. I'm want to use a while loop and a sentinel value of zero to stop the input. I would like the average to display to three decimal places, with the % s...
0
2016-06-05T14:32:07Z
37,643,762
<pre><code>total =0 counter = 0 while True: entry = int(input('Enter test score:')) if entry ==0: break total += entry counter += 1 average = (total/counter) print("The average score:",format(average, '.3f'),'%',sep='') </code></pre>
0
2016-06-05T15:45:50Z
[ "python", "while-loop", "average" ]
Is Cython/Jython an independent language?
37,643,172
<p>So I spent a lot of time trying to fugure out what <code>Cython</code> and <code>Jython</code> are and I'm still (more) confused as anyone who just started computer programming. I heard that <code>Cython</code> is an extension, but..is <em>also</em> and indepent language??</p> <p>What I <em>think</em> I've understo...
0
2016-06-05T14:44:55Z
37,643,279
<p>CPython is comparable to Jython. They're the implementation of the Python language. CPython is the de-facto standard and was written in C. Jython is written in Java and runs on the JVM. It also allows accessing the Java ecosystem to a great extent. There are also other implementation of the language, like PyPy or Py...
0
2016-06-05T14:55:31Z
[ "java", "python", "c", "jython", "cython" ]
Is Cython/Jython an independent language?
37,643,172
<p>So I spent a lot of time trying to fugure out what <code>Cython</code> and <code>Jython</code> are and I'm still (more) confused as anyone who just started computer programming. I heard that <code>Cython</code> is an extension, but..is <em>also</em> and indepent language??</p> <p>What I <em>think</em> I've understo...
0
2016-06-05T14:44:55Z
37,643,350
<p>Jython is a implementation of Python language on the Java Virtual Machine, so Jython is Python but is not CPython. Cython is an extension to CPython and has not much in common with Python except some similarities in Syntax.</p>
0
2016-06-05T15:01:33Z
[ "java", "python", "c", "jython", "cython" ]
Is Cython/Jython an independent language?
37,643,172
<p>So I spent a lot of time trying to fugure out what <code>Cython</code> and <code>Jython</code> are and I'm still (more) confused as anyone who just started computer programming. I heard that <code>Cython</code> is an extension, but..is <em>also</em> and indepent language??</p> <p>What I <em>think</em> I've understo...
0
2016-06-05T14:44:55Z
37,643,376
<p><a href="https://wiki.python.org/jython/JythonFaq/GeneralInfo" rel="nofollow"><strong>Jython FAQ:</strong></a> </p> <blockquote> <p>Jython is an <em>implementation</em> of the Python language for the Java platform. Jython 2.7 <em>implements the same language</em> as CPython 2.7, and nearly all of the Core Python ...
6
2016-06-05T15:04:53Z
[ "java", "python", "c", "jython", "cython" ]
Is Cython/Jython an independent language?
37,643,172
<p>So I spent a lot of time trying to fugure out what <code>Cython</code> and <code>Jython</code> are and I'm still (more) confused as anyone who just started computer programming. I heard that <code>Cython</code> is an extension, but..is <em>also</em> and indepent language??</p> <p>What I <em>think</em> I've understo...
0
2016-06-05T14:44:55Z
37,643,398
<p>Ok. Jython is an implementation of Python that converts python source code into java bytecode or object code as most people call it. So you basically write your programs using the python syntax, but the output of the source code when compiled to an object code is the java bytecode</p> <p>Cython on the other hand is...
1
2016-06-05T15:07:33Z
[ "java", "python", "c", "jython", "cython" ]
tkinter sticky=N+W Error: global name 'N' is not defined
37,643,258
<p>I am making a tkinter GUI but I am not getting why this error shows. Also, I am having trouble in understanding initializing Frame. Is that related to the error, maybe? I am still new to Python and need to understand more on how it works. Sorry, if the mistake will be basic, I am having a troubled mind. Your help wi...
-1
2016-06-05T14:53:02Z
37,643,362
<p>As the error mentions, the problem is that you are referencing a variable N (as well as W) which are not defined.</p> <p>These are variables defined in Tkinter, so you could do tk.N and tk.W, or alternatively just use the strings that those variables define, e.g.:</p> <pre><code> self.inputLabel.grid(row = 1, colu...
1
2016-06-05T15:03:45Z
[ "python", "python-2.7", "tkinter", "global" ]
Soup.find_all is only returning Some of the results in Python 3.5.1
37,643,280
<p>I'm trying to get all of the urls for thumbnails from my webpage that have the class = "thumb", but soup.find_all is only printing the most recent 22 or so.</p> <p>Here is the Code:</p> <pre><code>import requests from bs4 import BeautifulSoup r = requests.get("http://rayleighev.deviantart.com/gallery/44021661/Redd...
-1
2016-06-05T14:55:36Z
37,644,078
<p>I think you meant to ask about <em>following the pagination</em> and grabbing all the links in a list. Here is the implementation of that idea - use the <code>offset</code> parameter and grab links until there are no more links present incrementing the <code>offset</code> by 24 (number of links per page):</p> <pre>...
0
2016-06-05T16:16:07Z
[ "python", "python-3.x", "beautifulsoup", "python-requests" ]
Check boolean from another function
37,643,316
<p>I am trying to do something when a boolean from another function is set to "True". I tried using return(variable) but when it comes to the function that asks for the bool it always says False. I took a look here before asking this because I felt like this seems to be really basic stuff. But i couldn't find anything ...
-1
2016-06-05T14:58:37Z
37,643,389
<p>First of all, do not use a variable named <code>bool</code>. It's reserved by Python, such as like <code>str,list,int</code> etc.</p> <p>Second, <code>bool</code> is in global scope, so if you want to edit it in a function, you have to define it as <code>global</code>.</p> <pre><code>x = 0 bool1 = False def func...
-1
2016-06-05T15:06:23Z
[ "python", "boolean" ]
Check boolean from another function
37,643,316
<p>I am trying to do something when a boolean from another function is set to "True". I tried using return(variable) but when it comes to the function that asks for the bool it always says False. I took a look here before asking this because I felt like this seems to be really basic stuff. But i couldn't find anything ...
-1
2016-06-05T14:58:37Z
37,643,410
<p>Sticking to how you've written your code, you have two options. Option 1 is to use a global variable, making sure you include the <code>global</code> declaration in functions where you want to modify it:</p> <pre><code>x = 0 bool = False def functionA(x): global bool if x is 0: bool = True def fun...
1
2016-06-05T15:09:03Z
[ "python", "boolean" ]
Check boolean from another function
37,643,316
<p>I am trying to do something when a boolean from another function is set to "True". I tried using return(variable) but when it comes to the function that asks for the bool it always says False. I took a look here before asking this because I felt like this seems to be really basic stuff. But i couldn't find anything ...
-1
2016-06-05T14:58:37Z
37,643,429
<p><a href="https://docs.python.org/3.4/tutorial/controlflow.html#defining-functions" rel="nofollow">https://docs.python.org/3.4/tutorial/controlflow.html#defining-functions</a>:</p> <blockquote> <p>More precisely, all variable assignments in a function store the value in the local symbol table; whereas variable ref...
0
2016-06-05T15:10:51Z
[ "python", "boolean" ]
Not able to login to a website using requests python package
37,643,379
<p>I am using the following script to login to <a href="https://www.mbaco.com/login" rel="nofollow">https://www.mbaco.com/login</a>. While I am not getting any error, I can't access the protected pages of the website. Plz help.</p> <pre><code>import requests url = 'https://www.mbaco.com/login' payload = { '_us...
0
2016-06-05T15:05:10Z
37,647,024
<p>You have the wrong url, the post is to <code>https://www.mbaco.com/login_check</code>, it is also a good to add a user-agent:</p> <pre><code>import requests headers = {"User-Agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.75 Safari/537.36"} url = 'https://www.mbaco....
1
2016-06-05T21:37:13Z
[ "python", "beautifulsoup", "python-requests" ]
List Problems in 1 Dimensional Python Battleship
37,643,441
<p>I'm just starting to learn python and have come across some trouble when trying to program a simple 1-D version of single player battleship.</p> <p>2 things I can't seem to make work:</p> <ol> <li><p>I have a created a 1 dimensional list (which is the gameplay board), but need to display/print the indices of the r...
0
2016-06-05T15:12:59Z
37,643,604
<p>Good practice: set the board size to a variable so you can reference it regularly. Put this at the top</p> <pre><code>size = 5 # Can be changed later if you want to make the board bigger </code></pre> <p>Next, have your ship location be chosen based on that</p> <pre><code>ship = randint(0, size) </code></pre> <p...
1
2016-06-05T15:31:39Z
[ "python", "arrays" ]
List Problems in 1 Dimensional Python Battleship
37,643,441
<p>I'm just starting to learn python and have come across some trouble when trying to program a simple 1-D version of single player battleship.</p> <p>2 things I can't seem to make work:</p> <ol> <li><p>I have a created a 1 dimensional list (which is the gameplay board), but need to display/print the indices of the r...
0
2016-06-05T15:12:59Z
37,643,684
<p>To implement your two display functionalities, I would recommend just letting your <code>board</code> list just hold the display values, as you're not using it anywhere else anyway.</p> <pre><code>from random import randint ship=randint(1, 5) board = ['1', '2', '3', '4', '5'] print ("Let's play Battleship!") att...
1
2016-06-05T15:38:37Z
[ "python", "arrays" ]
Iterate python dictionary to assign value to table's fields
37,643,520
<p>Using an API I get a json dictionary as response in the form:</p> <pre><code>{"transacDet":[{"field1":6933434802,"field2":323499903,"field3":293483842}, {"field1":693433448,"field2":333400300,"field3":298334300}],"responseStatus" :{"statusMessage":"success","statusCode":0}} </code></pre> <p>I am looking to create ...
1
2016-06-05T15:23:55Z
37,643,610
<pre><code>a= {"transacDet":[{"field1":6933434802,"field2":323499903,"field3":293483842}, {"field1":693433448,"field2":333400300,"field3":298334300}],"responseStatus" :{"statusMessage":"success","statusCode":0}} import pandas as pd df =pd.DataFrame(a['transacDet']) df Out[11]: field1 field2 field3 0 ...
2
2016-06-05T15:32:05Z
[ "python", "json", "dictionary" ]
Iterate python dictionary to assign value to table's fields
37,643,520
<p>Using an API I get a json dictionary as response in the form:</p> <pre><code>{"transacDet":[{"field1":6933434802,"field2":323499903,"field3":293483842}, {"field1":693433448,"field2":333400300,"field3":298334300}],"responseStatus" :{"statusMessage":"success","statusCode":0}} </code></pre> <p>I am looking to create ...
1
2016-06-05T15:23:55Z
37,643,637
<p>By what I understad, you just to iterate the <code>transacDet</code> key:</p> <pre><code>import json parsed = json.loads('{"transacDet":[{"field1":6933434802,"field2":323499903,"field3":293483842}, {"field1":693433448,"field2":333400300,"field3":298334300}],"responseStatus" :{"statusMessage":"success","statusCode":...
0
2016-06-05T15:34:33Z
[ "python", "json", "dictionary" ]