qid int64 46k 74.7M | question stringlengths 54 37.8k | date stringlengths 10 10 | metadata listlengths 3 3 | response_j stringlengths 17 26k | response_k stringlengths 26 26k |
|---|---|---|---|---|---|
42,742,519 | I am new to programming and was trying to create a program in python that creates a staircase with size based on the user input. The program should appear as shown below:

This is the code I have so far;
```
steps = int(input('How many steps? '))
print('__')
fo... | 2017/03/12 | [
"https://Stackoverflow.com/questions/42742519",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7696748/"
] | To get the correct amount of steps, you have to change the for loop to:
```
for i in range(steps-1):
```
This is because you want to print the `|_`'s one less time than there are steps; your "top" step `__` already counts as one step.
The whole thing (changed some other things to make the formatting better):
```
s... | It is simpler to consider that `n` is the current step and given the step size (2) then you just need `2n` for your placement:
```
steps = 5
print('__')
for n in range(1, steps):
print(' '*n*2 + '|_')
print('_'*steps*2 + '|')
```
Output:
```
__
|_
|_
|_
|_
__________|
```
You can abstract ... |
42,742,519 | I am new to programming and was trying to create a program in python that creates a staircase with size based on the user input. The program should appear as shown below:

This is the code I have so far;
```
steps = int(input('How many steps? '))
print('__')
fo... | 2017/03/12 | [
"https://Stackoverflow.com/questions/42742519",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7696748/"
] | To get the correct amount of steps, you have to change the for loop to:
```
for i in range(steps-1):
```
This is because you want to print the `|_`'s one less time than there are steps; your "top" step `__` already counts as one step.
The whole thing (changed some other things to make the formatting better):
```
s... | ```
def stairs(steps):
print("__")
length = 1
for i in range(steps):
length += 1
print("%s|_" % (" "*(length+i)),)
print("%s|" % ("_"*(length+steps+1)),)
stairs(4)
```
Output:
```
__
|_
|_
|_
|_
__________|
``` |
42,742,519 | I am new to programming and was trying to create a program in python that creates a staircase with size based on the user input. The program should appear as shown below:

This is the code I have so far;
```
steps = int(input('How many steps? '))
print('__')
fo... | 2017/03/12 | [
"https://Stackoverflow.com/questions/42742519",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7696748/"
] | To get the correct amount of steps, you have to change the for loop to:
```
for i in range(steps-1):
```
This is because you want to print the `|_`'s one less time than there are steps; your "top" step `__` already counts as one step.
The whole thing (changed some other things to make the formatting better):
```
s... | You can do it via `while`.
`counter = 0
while counter < steps:
Create_stairs()
increase counter` |
42,742,519 | I am new to programming and was trying to create a program in python that creates a staircase with size based on the user input. The program should appear as shown below:

This is the code I have so far;
```
steps = int(input('How many steps? '))
print('__')
fo... | 2017/03/12 | [
"https://Stackoverflow.com/questions/42742519",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7696748/"
] | To get the correct amount of steps, you have to change the for loop to:
```
for i in range(steps-1):
```
This is because you want to print the `|_`'s one less time than there are steps; your "top" step `__` already counts as one step.
The whole thing (changed some other things to make the formatting better):
```
s... | Not sure what your exact question is. The patter of steps is:
* Step 1 -> 4 blanks
* Step 2 -> 6 blanks
* Step 3 -> 8 blanks
* Step n -> 2 + (2 \* n) blanks
steps = int(input('How many steps? ')) |
22,814,973 | im working on python application that requiring database connections..I had developed my application with sqlite3 but it start showing the error(the database is locked).. so I decided to use MySQL database instead.. and it is pretty good with no error..
the only one problem is that I need to ask every user using my app... | 2014/04/02 | [
"https://Stackoverflow.com/questions/22814973",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2980054/"
] | It depends (more "depends" in the answer).
If you need to share the data between the users of your application - you need a mysql database server somewhere setup, your application would need to have an access to it. And, the performance can really depend on the network - depends on how heavily would the application us... | If your application is a stand-alone system such that each user maintains their own private database then you have no alternative to install MySQL on each system that is running the application. ~~You cannot bundle MySQL into your application such that it does not require a separate installation.~~
There is an embedde... |
51,583,196 | I am learning python django i am developing one website but i am struggling with URL pattern
I am Sharing my code for URL pattern i don't understand where i am getting wrong
url.py
```
urlpatterns = [
url(r'^$',views.IndexView.as_view(),name='index'),
# /music/id/
url(r'^picture/(?P<pk>[0-9]+)$',views.De... | 2018/07/29 | [
"https://Stackoverflow.com/questions/51583196",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6246189/"
] | [](https://i.stack.imgur.com/xtW0A.png)
You can try this way:
```
floatingActionButton: FloatingActionButton(
onPressed: () {},
backgroundColor: Colors.red,
elevation: 0,
child: Container(
decoration: BoxDecoration(
... | floatingActionButton: FloatingActionButton(
onPressed: (){},
backgroundColor: Color(0xf0004451),
elevation: 10,
```
child: Container(
padding: const EdgeInsets.all(14.0),
decoration: BoxDecoration(
color: Colors.transparent,
borderRadius: BorderRadius.all(
Radius.circular(60),
),
... |
51,583,196 | I am learning python django i am developing one website but i am struggling with URL pattern
I am Sharing my code for URL pattern i don't understand where i am getting wrong
url.py
```
urlpatterns = [
url(r'^$',views.IndexView.as_view(),name='index'),
# /music/id/
url(r'^picture/(?P<pk>[0-9]+)$',views.De... | 2018/07/29 | [
"https://Stackoverflow.com/questions/51583196",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6246189/"
] | [](https://i.stack.imgur.com/xtW0A.png)
You can try this way:
```
floatingActionButton: FloatingActionButton(
onPressed: () {},
backgroundColor: Colors.red,
elevation: 0,
child: Container(
decoration: BoxDecoration(
... | ```
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
floatingActionButton: Container(
height: 70,
width: 70,
margin: const EdgeInsets.only(bottom: 10.0),
decoration: BoxDecoration(
color: Colors.transparent,
borderRadius: const BorderRadius.all(
... |
15,832,700 | I am newbie in python and I am trying to launch python script with a module writen on C. I am getting Segmentation fault (core dumped) error when I am trying to launch python script.
Here is a C code:
```
// input_device.c
#include "Python.h"
#include "input.h"
static PyObject* input_device_open(PyObject* self, Py... | 2013/04/05 | [
"https://Stackoverflow.com/questions/15832700",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1904234/"
] | Is it legitimate to return `NULL` without setting an exception, or making sure that one has been set by a function you have called? I thought that `NULL` was a signal that Python could go look for an exception to raise for the user.
I am not sure that the `Py_INCREF(pyfd);` is necessary; doesn't the object already hav... | Your function receives a tuple of arguments. You need to extract the integer from the tuple:
```
static PyObject* input_device_open(PyObject* self, PyObject* args)
{
int fd, nr;
PyObject* pyfd;
if (!PyArg_ParseTuple(args, "i", &nr))
return NULL;
``` |
54,366,675 | i have a list like below:
```
[3,2,4,5]
```
and i want a list like below:
```
[['1','2','3'],['1','2'],['1','2','3','4'],['1','2','3','4','5']]
```
i mean i want to have a list that is created by the count of another list.
I want to iterate each with string.
how can i write it in python
i tried this code:
```
... | 2019/01/25 | [
"https://Stackoverflow.com/questions/54366675",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6655937/"
] | You can use `range` with `list`, and list comprehension:
```
>>> a = [3, 2, 4, 5]
>>> [list(range(1, x+1)) for x in a]
[[1, 2, 3], [1, 2], [1, 2, 3, 4], [1, 2, 3, 4, 5]
```
And to make all strings, add `map` with `str`:
```
>>>[list(map(str, range(1, x+1))) for x in a]
[['1', '2', '3'], ['1', '2'], ['1', '2', '3', ... | try this code. I tried to make as easy as possible
```
lol=[3,2,4,5]
ans=[]
temp=[]
for i in lol:
for j in range(1,i+1):
temp.append(j)
ans.append(temp)
temp=[]
print(ans)
```
Hope it helps |
42,183,476 | Can someone please help me with the python equivalent of the curl command:
python equivalent of `curl -X POST -F "name=blahblah" -F "[email protected]"`
I would like to you python requests module, but I am not clear on the options to use. | 2017/02/12 | [
"https://Stackoverflow.com/questions/42183476",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7552038/"
] | It depends on how you are going to use this reference.
1) There is no straight way to get component DOM reference within template:
```
import {Directive, Input, ElementRef, EventEmitter, Output, OnInit} from '@angular/core';
@Directive({selector: '[element]', exportAs: 'element'})
export class NgElementRef imple... | As of Angular 8, the following provides access to the ElementRef and native element.
```
/**
* Export the ElementRef of the selected element for use with template references.
*
* @example
* <button mat-button #button="appElementRef" appElementRef></button>
*/
@Directive({
selector: '[appElementRef]',
expo... |
43,192,626 | I'm new to pandas & numpy. I'm running a simple program
```
labels = ['a','b','c','d','e']
s = Series(randn(5),index=labels)
print(s)
```
getting the following error
```
s = Series(randn(5),index=labels) File "C:\Python27\lib\site-packages\pandas\core\series.py", line 243, in
__init__
raise_cast_failure=... | 2017/04/03 | [
"https://Stackoverflow.com/questions/43192626",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1385691/"
] | I suspect you have your imports wrong.
If you add this to your code:
```
from pandas import Series
from numpy.random import randn
labels = ['a','b','c','d','e']
s = Series(randn(5),index=labels)
print(s)
a 0.895322
b 0.949709
c -0.502680
d -0.511937
e -1.550810
dtype: float64
```
It runs fine.
That ... | It seems you need [`numpy.random.rand`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.rand.html) for random `floats` or [`numpy.random.randint`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.randint.html) for random `integers`:
```
import pandas as pd
import numpy as np
np.rand... |
21,729,196 | I've got the following dictionary:
```py
d = {
'A': {
'param': {
'1': {
'req': True,
},
'2': {
'req': True,
},
},
},
'B': {
'param': {
'3': {
'req': True,
},
... | 2014/02/12 | [
"https://Stackoverflow.com/questions/21729196",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2047097/"
] | The generator expressions you assign to `req[key]` binds on the `key` variable. But `key` changes from 'A' to 'B' in the loop. When you iterate over the first generator expression, it will evaluate `key` to 'B' in its `if` condition, even though `key` was 'A' when you created it.
The conventional way to bind to a vari... | This is because upon execution of the generator, the *latest* value of `key` is used.
Suppose the `for key in d:` iterates over the keys in the order `'A', 'B'`, the 1st generator is supposed to work with `key = 'A'`, but due to closure issues, it uses the item with `'B'` as key. And this has no `'1'` sub-entry.
Even... |
30,871,488 | The familiar pythonic slicing conventions of `myList[-1:][0]` and `myList[-1]` are not available for Mongoengine listFields because it does not support negative indices. Is there an elegant way to get the last element of a list?
Error verbiage for posterity:
>
> `IndexError: Cursor instances do not support negativ... | 2015/06/16 | [
"https://Stackoverflow.com/questions/30871488",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2355364/"
] | You need to use [$location.path()](https://docs.angularjs.org/api/ng/service/$location)
```
// given url http://blo.c/news
var path = $location.path();
// => "/news"
```
If you are using HTML5 mode you must ensure [$locationProvider.html5Mode(true)](https://docs.angularjs.org/guide/$location#html5-mode) is set so `$... | Use the `$location.path` function to get the url. To get what's after the url, use `split`
```
$location.path.split(/\{1}/)[1]
``` |
30,871,488 | The familiar pythonic slicing conventions of `myList[-1:][0]` and `myList[-1]` are not available for Mongoengine listFields because it does not support negative indices. Is there an elegant way to get the last element of a list?
Error verbiage for posterity:
>
> `IndexError: Cursor instances do not support negativ... | 2015/06/16 | [
"https://Stackoverflow.com/questions/30871488",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2355364/"
] | You need to use [$location.path()](https://docs.angularjs.org/api/ng/service/$location)
```
// given url http://blo.c/news
var path = $location.path();
// => "/news"
```
If you are using HTML5 mode you must ensure [$locationProvider.html5Mode(true)](https://docs.angularjs.org/guide/$location#html5-mode) is set so `$... | ```
const URL = '/seg1/?key=value';
$location.path();// will return URI segment (in above URL it returns /seg1 ).
$location.search(); // getter will fetch URL segment after ? symbol.
//(in above URL it returns {key:value} object ).
```
Official Doc: <https://docs.angularjs.org/guide/$location> |
30,871,488 | The familiar pythonic slicing conventions of `myList[-1:][0]` and `myList[-1]` are not available for Mongoengine listFields because it does not support negative indices. Is there an elegant way to get the last element of a list?
Error verbiage for posterity:
>
> `IndexError: Cursor instances do not support negativ... | 2015/06/16 | [
"https://Stackoverflow.com/questions/30871488",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2355364/"
] | Use the `$location.path` function to get the url. To get what's after the url, use `split`
```
$location.path.split(/\{1}/)[1]
``` | ```
const URL = '/seg1/?key=value';
$location.path();// will return URI segment (in above URL it returns /seg1 ).
$location.search(); // getter will fetch URL segment after ? symbol.
//(in above URL it returns {key:value} object ).
```
Official Doc: <https://docs.angularjs.org/guide/$location> |
54,701,639 | I have a python operator in my DAG. The python callable function is returning a bool value. But, when I run the DAG, I get the below error.
>
> TypeError: 'bool' object is not callable
>
>
>
I modified the function to return nothing but then again I keep getting the below error
>
> ERROR - 'NoneType' object is ... | 2019/02/15 | [
"https://Stackoverflow.com/questions/54701639",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4017926/"
] | The argument name gives it away. You are passing the result of a call rather than a callable.
```
python_callable=check_poke(129600,600)
```
The second error states that the callable is called with 25 arguments. So a `lambda:` won't work. The following would work but ignoring 25 arguments is really questionable.
``... | Agree with **@Dan D.** for the issue; but it's perplexing why his solution didn't work (it certainly works in `python` *shell*)
See if this finds you any luck (its just verbose variant of **@Dan D.**'s solution)
```
from typing import Callable
# your original check_poke function
def check_poke(arg_1: int, arg_2: int... |
54,701,639 | I have a python operator in my DAG. The python callable function is returning a bool value. But, when I run the DAG, I get the below error.
>
> TypeError: 'bool' object is not callable
>
>
>
I modified the function to return nothing but then again I keep getting the below error
>
> ERROR - 'NoneType' object is ... | 2019/02/15 | [
"https://Stackoverflow.com/questions/54701639",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4017926/"
] | The argument name gives it away. You are passing the result of a call rather than a callable.
```
python_callable=check_poke(129600,600)
```
The second error states that the callable is called with 25 arguments. So a `lambda:` won't work. The following would work but ignoring 25 arguments is really questionable.
``... | The code expects a callable, not the result (as already pointed out).
You could use [functools.Partial](https://docs.python.org/3/library/functools.html) to fill out the arguments:
```
from functools import partial
def check_poke(threshold,sleep_interval):
flag=snowflake_poke(1000,10).poke()
return flag
fun... |
29,829,470 | I'm trying to get range-rings on my map, with the position of the image above the user's location, but the map doesn't appear when I test it and the user's location doesn't seem to show up on the map. I don't know what went wrong, I followed a tutorial on a website.
This is the code:
```html
<!DOCTYPE html>
<html>
... | 2015/04/23 | [
"https://Stackoverflow.com/questions/29829470",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3832981/"
] | geolocation runs asynchronously.
You may either create the map/marker when it returns a result or define a default-coordinate and update map/marker when it returns a result.
The 2nd approach is preferable, because you wouldn't get a map at all when geolocation fails.
A simple implementation using a MVCObject, which ... | I think you should include your Google Api key.
Try to add the script below :
```
<script async defer src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap"
type="text/javascript"></script>
``` |
53,405,006 | I am trying to set up a Dockerfile for my project and am unsure how to set a JAVA\_HOME within the container.
```
FROM python:3.6
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
COPY . /app
# Install any needed packages specified in requirements.txt
RUN... | 2018/11/21 | [
"https://Stackoverflow.com/questions/53405006",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6465715/"
] | You need to actually install Java inside your container, but I would suggest rather finding a Pyspark docker image, or adding Python to the Openjdk images so that you don't need to mess with too many environment variables
More specifically, `JAVA_HOME=/Library/Java/JavaVirtualMachines` is a only available as a path to... | To set environment variables, you can declare them in your dockerfile like so:
```
ENV JAVA_HOME="foo"
```
or
```
ENV JAVA_HOME foo
```
In fact, you already set an environment variable in the example you posted.
See [documentation](https://docs.docker.com/engine/reference/builder/#env) for more details. |
49,564,238 | I have below piece of code in python which I am using to get the component name of the JIRA issue some of them are single value in component field and some of them are multiple values in component field. My issue is that component field could have values with different name e.g R ABC 1.1 , R Aiapara 2.3A1(Active) etc.I... | 2018/03/29 | [
"https://Stackoverflow.com/questions/49564238",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1513848/"
] | Using regex:
```
import re
s1 = "R ABC 4.4"
s2 = "R Ciapara 4.4A1(Active)"
print(re.findall(r"\d+\.\d+", s1))
print(re.findall(r"\d+\.\d+", s2))
```
**Output:**
```
['4.4']
['4.4']
``` | I feel like I am not quite understanding your question, so I will try to answer as best I can, but feel free to correct me if I get anything wrong.
This function will get all the numbers from the string in a list:
```
def getNumber(string):
numbers = ".0123456789"
result = []
isNumber = False
for i in... |
28,570,268 | My file contains this format [{"a":1, "c":4},{"b":2, "d":5}] and I want to read this file into a list in python. The list items should be {"a":1, "c":4} and {"b":2, "d":5}. I tried to read into a string and then typecasting into a list but that is not helping. It is reading character by character. | 2015/02/17 | [
"https://Stackoverflow.com/questions/28570268",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4394027/"
] | You can "convert" a string that contains a list to an actual list like this
```
>>> import ast
>>> ast.literal_eval('[{"a":1, "c":4},{"b":2, "d":5}]')
[{'a': 1, 'c': 4}, {'b': 2, 'd': 5}]
```
You can of course sub out the literal string for the data you read from file | Another, more dirty option is this (it will produce list of strings):
```
a = str('[{"a":1, "c":4},{"b":2, "d":5}]')
b = list()
for i in a.replace('[','').replace(']','').split(sep='},'):
b.append(i+'}')
b[len(b)-1] = b[len(b)-1].replace('}}','}')
for i in b:
i
'{"a":1, "c":4}'
'{"b":2, "d":5}'
```
Since... |
28,570,268 | My file contains this format [{"a":1, "c":4},{"b":2, "d":5}] and I want to read this file into a list in python. The list items should be {"a":1, "c":4} and {"b":2, "d":5}. I tried to read into a string and then typecasting into a list but that is not helping. It is reading character by character. | 2015/02/17 | [
"https://Stackoverflow.com/questions/28570268",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4394027/"
] | You can "convert" a string that contains a list to an actual list like this
```
>>> import ast
>>> ast.literal_eval('[{"a":1, "c":4},{"b":2, "d":5}]')
[{'a': 1, 'c': 4}, {'b': 2, 'd': 5}]
```
You can of course sub out the literal string for the data you read from file | Use the json module to load json data. Since the json data is a list, it will be converted to a list in python when you call `json.load`:
```
import json
with open(path_to_jsonfile, 'r') as jsonfile:
jsonlist = json.load(jsonfile)
for listitem in jsonlist:
print listitem
```
The result should be:
```
{u'a'... |
3,172,236 | I am writing a piece of code which will extract words from running text. This text can contain delimiters like \r,\n etc. which might be there in text.
I want to discard all these delimiters and only extract full words. How can I do this with Python? any library available for crunching text in python? | 2010/07/03 | [
"https://Stackoverflow.com/questions/3172236",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/348663/"
] | Assuming your definition of "word" agrees with that of the regular expression module (`re`), that is, letters, digits and underscores, it's easy:
```
import re
fullwords = re.findall(r'\w+', thetext)
```
where `thetext` is the string in question (e.g., coming from an `f.read()` of a file object `f` open for reading,... | Assuming your delimiters are whitespace characters (like space, `\r` and `\n`), then basic [`str.split()`](http://docs.python.org/library/stdtypes.html#str.split) does what you want:
```
>>> "asdf\nfoo\r\nbar too\tbaz".split()
['asdf', 'foo', 'bar', 'too', 'baz']
``` |
74,200,925 | I'm new to python and having problems with summing up the numbers inside an element and then adding them together to get a total value.
Example of what I'm trying to do:
```
list = {'area1': [395.0, 212.0], 'area2': [165.0, 110.0]}
'area1': [395.0 * 212.0], 'area2': [165.0 * 110.0]
'area1': [83740], 'area2': [18150... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74200925",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20248393/"
] | You can use a generator expression to multiply the pairs of values in your dictionary, then `sum` the output of that:
```py
lst = {'area1': [395.0, 212.0], 'area2': [165.0, 110.0]}
total = sum(v[0]*v[1] for v in lst.values())
# 101890.0
``` | You can find the area using list comprehension.
Iterate through `lst.values()` -> `dict_values([[395.0, 212.0], [165.0, 110.0]])` and multiply the elements. Finally, use `sum` to find out the total.
```
lst = {'area1': [395.0, 212.0], 'area2': [165.0, 110.0]}
area = sum([i[0]*i[1] for i in lst.values()])
# 101890.0
... |
74,200,925 | I'm new to python and having problems with summing up the numbers inside an element and then adding them together to get a total value.
Example of what I'm trying to do:
```
list = {'area1': [395.0, 212.0], 'area2': [165.0, 110.0]}
'area1': [395.0 * 212.0], 'area2': [165.0 * 110.0]
'area1': [83740], 'area2': [18150... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74200925",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20248393/"
] | You can use a generator expression to multiply the pairs of values in your dictionary, then `sum` the output of that:
```py
lst = {'area1': [395.0, 212.0], 'area2': [165.0, 110.0]}
total = sum(v[0]*v[1] for v in lst.values())
# 101890.0
``` | The answer with sum, map, and a lambda is probally the best for just areas.
Give this a try if there are more dimensions:
this approach scales with dimensions collected (areas and volumes). We can use the reduce function with a lambda expression to handle multidimensional situations (i.e. you collect LxWxH and want t... |
74,200,925 | I'm new to python and having problems with summing up the numbers inside an element and then adding them together to get a total value.
Example of what I'm trying to do:
```
list = {'area1': [395.0, 212.0], 'area2': [165.0, 110.0]}
'area1': [395.0 * 212.0], 'area2': [165.0 * 110.0]
'area1': [83740], 'area2': [18150... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74200925",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20248393/"
] | You can use a generator expression to multiply the pairs of values in your dictionary, then `sum` the output of that:
```py
lst = {'area1': [395.0, 212.0], 'area2': [165.0, 110.0]}
total = sum(v[0]*v[1] for v in lst.values())
# 101890.0
``` | I think something like this will do the trick
```
from functools import reduce
total = sum([reduce(lambda x, y: x*y, area) for area in floorAreaList.values()])
```
with `values()` you get the values of the dictionary and then with the `lambda` you multiply every element and in the end `sum` them. |
74,200,925 | I'm new to python and having problems with summing up the numbers inside an element and then adding them together to get a total value.
Example of what I'm trying to do:
```
list = {'area1': [395.0, 212.0], 'area2': [165.0, 110.0]}
'area1': [395.0 * 212.0], 'area2': [165.0 * 110.0]
'area1': [83740], 'area2': [18150... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74200925",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20248393/"
] | The answer with sum, map, and a lambda is probally the best for just areas.
Give this a try if there are more dimensions:
this approach scales with dimensions collected (areas and volumes). We can use the reduce function with a lambda expression to handle multidimensional situations (i.e. you collect LxWxH and want t... | You can find the area using list comprehension.
Iterate through `lst.values()` -> `dict_values([[395.0, 212.0], [165.0, 110.0]])` and multiply the elements. Finally, use `sum` to find out the total.
```
lst = {'area1': [395.0, 212.0], 'area2': [165.0, 110.0]}
area = sum([i[0]*i[1] for i in lst.values()])
# 101890.0
... |
74,200,925 | I'm new to python and having problems with summing up the numbers inside an element and then adding them together to get a total value.
Example of what I'm trying to do:
```
list = {'area1': [395.0, 212.0], 'area2': [165.0, 110.0]}
'area1': [395.0 * 212.0], 'area2': [165.0 * 110.0]
'area1': [83740], 'area2': [18150... | 2022/10/25 | [
"https://Stackoverflow.com/questions/74200925",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20248393/"
] | The answer with sum, map, and a lambda is probally the best for just areas.
Give this a try if there are more dimensions:
this approach scales with dimensions collected (areas and volumes). We can use the reduce function with a lambda expression to handle multidimensional situations (i.e. you collect LxWxH and want t... | I think something like this will do the trick
```
from functools import reduce
total = sum([reduce(lambda x, y: x*y, area) for area in floorAreaList.values()])
```
with `values()` you get the values of the dictionary and then with the `lambda` you multiply every element and in the end `sum` them. |
15,497,896 | I am very new to programming and am converting a fortran90 code into python 2.7. I have done fairly well with it so far but have hit a difficult spot. I need to write this subroutine in Python but I don't understand the fortran notation and can't find any information on what the python equivalent of the Read(1,\*) line... | 2013/03/19 | [
"https://Stackoverflow.com/questions/15497896",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | In fortran, `open(1,FILE=TRIM(filenameBC),RECL=2000)` opens the file with name `filenameBC`. The `TRIM` part is unnecessary as the fortran runtime library will do that for you (it's python equivalent is `filenameBC.rstrip()`). The `RECL=2000` part here is also a little fishy. I don't think that it does anything here --... | `READ(1,*)` is reading .... something out of your file and not storing it, i.e. just throwing it away. All those `READ(1,*)` statements are just a way of scrolling through the file until you get to the data you actually need. (Not the most compact way to code this, by the way. Whoever wrote this FORTRAN code may have b... |
23,566,970 | I have been using argparse in a program I am writing however it doesnt seem to create the stated output file.
My code is:
```
parser.add_argument("-o", "--output", action='store', dest='output', help="Directs the output to a name of your choice")
with open(output, 'w') as output_file:
output_file.write("... | 2014/05/09 | [
"https://Stackoverflow.com/questions/23566970",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3616869/"
] | You are missing the bit where the arguments are actually parsed:
```
parser.add_argument("-o", "--output", help="Directs the output to a name of your choice")
args = parser.parse_args()
with open(args.output, 'w') as output_file:
output_file.write("%s\n" % item)
```
parser.parse\_args() will give you an object f... | When I run your script I get:
```
Traceback (most recent call last):
File "stack23566970.py", line 31, in <module>
with open(output, 'w') as output_file:
NameError: name 'output' is not defined
```
There's no place in your script that does `output = ...`.
We can correct that with:
```
with open(args.output,... |
23,566,970 | I have been using argparse in a program I am writing however it doesnt seem to create the stated output file.
My code is:
```
parser.add_argument("-o", "--output", action='store', dest='output', help="Directs the output to a name of your choice")
with open(output, 'w') as output_file:
output_file.write("... | 2014/05/09 | [
"https://Stackoverflow.com/questions/23566970",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3616869/"
] | You are missing the bit where the arguments are actually parsed:
```
parser.add_argument("-o", "--output", help="Directs the output to a name of your choice")
args = parser.parse_args()
with open(args.output, 'w') as output_file:
output_file.write("%s\n" % item)
```
parser.parse\_args() will give you an object f... | I think you almost had the most correct answer. The only problem is `output_file` was not read from the args:
```
parser.add_argument("-o", "--output", action='store',
type=argparse.FileType('w'), dest='output',
help="Directs the output to a name of your choice")
#output_file i... |
23,566,970 | I have been using argparse in a program I am writing however it doesnt seem to create the stated output file.
My code is:
```
parser.add_argument("-o", "--output", action='store', dest='output', help="Directs the output to a name of your choice")
with open(output, 'w') as output_file:
output_file.write("... | 2014/05/09 | [
"https://Stackoverflow.com/questions/23566970",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3616869/"
] | I think you almost had the most correct answer. The only problem is `output_file` was not read from the args:
```
parser.add_argument("-o", "--output", action='store',
type=argparse.FileType('w'), dest='output',
help="Directs the output to a name of your choice")
#output_file i... | When I run your script I get:
```
Traceback (most recent call last):
File "stack23566970.py", line 31, in <module>
with open(output, 'w') as output_file:
NameError: name 'output' is not defined
```
There's no place in your script that does `output = ...`.
We can correct that with:
```
with open(args.output,... |
50,447,751 | I'm trying to retrieve last month's media posts from an Instagram Business profile I manage, by using `'since'` and `'until'`, but it doesn't seem to work properly as the API returns posts which are out of the time range I selected.
I'm using the following string to call the API:
```
business_profile_id/media?fields... | 2018/05/21 | [
"https://Stackoverflow.com/questions/50447751",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8542692/"
] | Unfortunately the `since` and `until` parameters are not supported on this endpoint and this endpoint has only support cursor based pagination. The only way to do what I wish to do is to load each page of results individually using the `before` and `after` cursors provided in the API response. | For your task, I would recommend you to not use InstagramAPI library. I will show you a simple solution for this using [instabot](https://github.com/instagrambot/instabot) library. For pip installation of this library, use this command:
`pip install instabot`
Use the following python code to get the media within the ... |
72,470,453 | ```
import os
import sys, getopt
import signal
import time
from edge_impulse_linux.audio import AudioImpulseRunner
DEFAULT_THRESHOLD = 0.60
my_threshold = DEFAULT_THRESHOLD
runner = None
def signal_handler(sig, frame):
print('Interrupted')
if (runner):
runner.stop()
sys.exit(0)
signal.signal(signal.SIGINT, sign... | 2022/06/02 | [
"https://Stackoverflow.com/questions/72470453",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19253158/"
] | [`some`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some) short-circuits after finding the first match so it doesn't necessarily have to iterate over the whole array of objects. And it also returns a boolean which satisfies your use-case.
```js
const query1 = ['empid','Name'... | Use `_.isEqual(object, other);`
It may help you. |
37,277,206 | Currently while using `babel-plugin-react-intl`, separate json for every component is created with 'id', 'description' and 'defaultMessage'. What I need is that only a single json to be created which contains a single object with all the 'id' as the 'key' and 'defaultMessage' as the 'value'
Present situation:
`Compon... | 2016/05/17 | [
"https://Stackoverflow.com/questions/37277206",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5380918/"
] | There is a [translations manager](https://github.com/GertjanReynaert/react-intl-translations-manager) that will do this.
Or for a custom option see below
---
The script below which is based on this [script](https://github.com/emmenko/redux-react-router-async-example/blob/master/scripts/i18nToXliff.js) goes through... | You can use [babel-plugin-react-intl-extractor](https://github.com/Bolid1/babel-plugin-react-intl-extractor) for aggregate your translations in single file. Also it provides autorecompile translation files on each change of your messages. |
33,111,338 | I am trying to find out the sum of multiples of two numbers using python.I have done it already. I just want to solve it using lambda functions.
Without lambda code
```
def sumMultiples(num, limit):
sum = 0
for i in xrange(num, limit, num):
sum += i
return sum
def sum(limit):
return (sumMu... | 2015/10/13 | [
"https://Stackoverflow.com/questions/33111338",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5442186/"
] | Try this code:
```
a = input("enter first number\n")
b= input("enter second number\n")
limit=[]
limit.append(a)
limit.append(b)
natNo=range(1,1000)
xyz = []
for i in limit:
xyz +=filter(lambda x: x == i or x % i==0, natNo)
set = {}
map(set.__setitem__, xyz, [])
nums=set.keys()
print "the multiples of the given ... | ```
limit = 1000
a=lambda num, limit: sum([i for i in xrange(num, limit, num)])
print a(3,limit)+a(5,limit)-a(15,limit)
``` |
42,562,876 | I'm trying to read the frames of an .mov file using OpenCV 3.2 (from the [menpo conda channel](https://anaconda.org/menpo/opencv3)). I'm using Python 3.5.3 through Anaconda on an Ubuntu 16.04 64-bit setup.
Problem is, I get the following error message from OpenCV when it hits the `cap.read()` call, and the loop immedi... | 2017/03/02 | [
"https://Stackoverflow.com/questions/42562876",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13604/"
] | Solved the problem by getting around it entirely.
Used the [opencv-feedstock](https://github.com/conda-forge/opencv-feedstock) recipe of OpenCV for conda-forge. In the `recipe` folder is the build information for conda. I modified the `build.sh` file, changing the following options:
```
-DBUILD_PNG=1
-DBUILD_JPEG=1
-... | I faced the same problem with Anaconda private env & Python 3.5 on Ubuntu 16.04 .
Initially installed Opencv3 using
```
conda install -c menpo opencv3
```
Solution:
1. Remove Opencv3 `conda remove opencv3`
2. Install Opencv3 using `pip install opencv-contrib-python`
If the problem still persists:
1. Uninstall Op... |
19,609,456 | Is there any way of creating a simple java(or c,c ++, python) program that prints 3 (outputs the 3) when given input=6 and it gives output=6 when given input=3 without using "if conditions" ? | 2013/10/26 | [
"https://Stackoverflow.com/questions/19609456",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2829141/"
] | Assuming you're happy for it to produce other outputs on inputs that aren't 6 or 3, then you can just compute 9-x. | You can always just use a switch-case statement. Also, if you only want those two answers, you could also take the input as an int and do 9-[your int] and print that answer. |
19,609,456 | Is there any way of creating a simple java(or c,c ++, python) program that prints 3 (outputs the 3) when given input=6 and it gives output=6 when given input=3 without using "if conditions" ? | 2013/10/26 | [
"https://Stackoverflow.com/questions/19609456",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2829141/"
] | Assuming you're happy for it to produce other outputs on inputs that aren't 6 or 3, then you can just compute 9-x. | without if or without control flow statement/condition statement ?
you could use switch statement
```
private void tes(int i) {
switch (i) {
///give output 6 where input is 3
case 3:
System.out.println(6);
break;
///give output 3 where input is 6
case 6:
... |
19,609,456 | Is there any way of creating a simple java(or c,c ++, python) program that prints 3 (outputs the 3) when given input=6 and it gives output=6 when given input=3 without using "if conditions" ? | 2013/10/26 | [
"https://Stackoverflow.com/questions/19609456",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2829141/"
] | Assuming you're happy for it to produce other outputs on inputs that aren't 6 or 3, then you can just compute 9-x. | You can use the XOR bit operation. It compares pairs of bits and returns 0 if bits are equals and 1 if bits are different.
We have `3 = 011b` and `6 = 110b`. This numbers differ by 1 and 3 digit (bit), so XOR mask will be `101b = 5`.
Code example:
```
public static int testMethod(int value){
return System.out.... |
19,609,456 | Is there any way of creating a simple java(or c,c ++, python) program that prints 3 (outputs the 3) when given input=6 and it gives output=6 when given input=3 without using "if conditions" ? | 2013/10/26 | [
"https://Stackoverflow.com/questions/19609456",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2829141/"
] | You can always just use a switch-case statement. Also, if you only want those two answers, you could also take the input as an int and do 9-[your int] and print that answer. | without if or without control flow statement/condition statement ?
you could use switch statement
```
private void tes(int i) {
switch (i) {
///give output 6 where input is 3
case 3:
System.out.println(6);
break;
///give output 3 where input is 6
case 6:
... |
19,609,456 | Is there any way of creating a simple java(or c,c ++, python) program that prints 3 (outputs the 3) when given input=6 and it gives output=6 when given input=3 without using "if conditions" ? | 2013/10/26 | [
"https://Stackoverflow.com/questions/19609456",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2829141/"
] | You can use the XOR bit operation. It compares pairs of bits and returns 0 if bits are equals and 1 if bits are different.
We have `3 = 011b` and `6 = 110b`. This numbers differ by 1 and 3 digit (bit), so XOR mask will be `101b = 5`.
Code example:
```
public static int testMethod(int value){
return System.out.... | without if or without control flow statement/condition statement ?
you could use switch statement
```
private void tes(int i) {
switch (i) {
///give output 6 where input is 3
case 3:
System.out.println(6);
break;
///give output 3 where input is 6
case 6:
... |
63,067,003 | I'm a beginner in python but I need to fix this small mistake. I tried different ways to fix it by changing the indentation. Maybe I'm overlooking something? The error is attached. Any help is much appreciated! Thank you
```
if(pretrained_weights):
model.load_weights(pretrained_weights)
print('*************Using... | 2020/07/24 | [
"https://Stackoverflow.com/questions/63067003",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13986513/"
] | Here you go.
```
if(pretrained_weights):
model.load_weights(pretrained_weights)
print('*************Using pretrained weights****************')
return model
``` | My solution:
```
if(pretrained_weights):
model.load_weights(pretrained_weights)
print('*************Using pretrained weights****************')
return model
``` |
63,067,003 | I'm a beginner in python but I need to fix this small mistake. I tried different ways to fix it by changing the indentation. Maybe I'm overlooking something? The error is attached. Any help is much appreciated! Thank you
```
if(pretrained_weights):
model.load_weights(pretrained_weights)
print('*************Using... | 2020/07/24 | [
"https://Stackoverflow.com/questions/63067003",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13986513/"
] | I don't know if you are a beginner or not but hope this helps:
```
if(pretrained_weights):
model.load_weights(pretrained_weights)
print('*************Using pretrained weights****************')
return model
``` | My solution:
```
if(pretrained_weights):
model.load_weights(pretrained_weights)
print('*************Using pretrained weights****************')
return model
``` |
21,721,558 | I am working on setting up the pyramid framework on python3.3 virtual env.
For the database connection I use MySQL Connector/Python (SQLAlchemy).
I came across with the problem:
When I try to select records form the database I get the following:
`[Wed Feb 12 09:20:34.373204 2014] [:error] [pid 29351] [remote 127.0... | 2014/02/12 | [
"https://Stackoverflow.com/questions/21721558",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2304257/"
] | Somehow, my computer was one year behind the actual time.
I adjusted to the correct time and the time zone.
I closed and open Google Chrome. Problem was fixed. | The problem is basically on older version of OS e.g. Windows-XP with SP-II. SHA-2 algorithm has been used to generate SSL certificates which is not in range of older version of OS.
There are two solutions for the problem as:
1. Upgrade the OS. Use another OS or upgrade existing one (with SP-III). or
2. Generate new S... |
21,721,558 | I am working on setting up the pyramid framework on python3.3 virtual env.
For the database connection I use MySQL Connector/Python (SQLAlchemy).
I came across with the problem:
When I try to select records form the database I get the following:
`[Wed Feb 12 09:20:34.373204 2014] [:error] [pid 29351] [remote 127.0... | 2014/02/12 | [
"https://Stackoverflow.com/questions/21721558",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2304257/"
] | I found a [related thread](https://productforums.google.com/forum/#!topic/chrome/5-Bf0o6YxgM) in a Google Chrome forum.
I think that the technology responsible for catching this is [HTTP Strict Transport Security](http://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security);
It looks like one of your extensions is in... | the solution consists in activating a flag for ignoring errors caused by certificates,
does not ignore the certificate itself but only the consequent error,
that is obtained by launching the binary with a specific parameter,
for your own reference: <http://www.technonsense.com/2014/04/chrome-ssl-error-solution/>
the ... |
21,721,558 | I am working on setting up the pyramid framework on python3.3 virtual env.
For the database connection I use MySQL Connector/Python (SQLAlchemy).
I came across with the problem:
When I try to select records form the database I get the following:
`[Wed Feb 12 09:20:34.373204 2014] [:error] [pid 29351] [remote 127.0... | 2014/02/12 | [
"https://Stackoverflow.com/questions/21721558",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2304257/"
] | I found a [related thread](https://productforums.google.com/forum/#!topic/chrome/5-Bf0o6YxgM) in a Google Chrome forum.
I think that the technology responsible for catching this is [HTTP Strict Transport Security](http://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security);
It looks like one of your extensions is in... | The problem is basically on older version of OS e.g. Windows-XP with SP-II. SHA-2 algorithm has been used to generate SSL certificates which is not in range of older version of OS.
There are two solutions for the problem as:
1. Upgrade the OS. Use another OS or upgrade existing one (with SP-III). or
2. Generate new S... |
21,721,558 | I am working on setting up the pyramid framework on python3.3 virtual env.
For the database connection I use MySQL Connector/Python (SQLAlchemy).
I came across with the problem:
When I try to select records form the database I get the following:
`[Wed Feb 12 09:20:34.373204 2014] [:error] [pid 29351] [remote 127.0... | 2014/02/12 | [
"https://Stackoverflow.com/questions/21721558",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2304257/"
] | Somehow, my computer was one year behind the actual time.
I adjusted to the correct time and the time zone.
I closed and open Google Chrome. Problem was fixed. | the solution consists in activating a flag for ignoring errors caused by certificates,
does not ignore the certificate itself but only the consequent error,
that is obtained by launching the binary with a specific parameter,
for your own reference: <http://www.technonsense.com/2014/04/chrome-ssl-error-solution/>
the ... |
21,721,558 | I am working on setting up the pyramid framework on python3.3 virtual env.
For the database connection I use MySQL Connector/Python (SQLAlchemy).
I came across with the problem:
When I try to select records form the database I get the following:
`[Wed Feb 12 09:20:34.373204 2014] [:error] [pid 29351] [remote 127.0... | 2014/02/12 | [
"https://Stackoverflow.com/questions/21721558",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2304257/"
] | Somehow, my computer was one year behind the actual time.
I adjusted to the correct time and the time zone.
I closed and open Google Chrome. Problem was fixed. | This problem happens because your system datetime is wrong. Update your window datetime correctly. |
21,721,558 | I am working on setting up the pyramid framework on python3.3 virtual env.
For the database connection I use MySQL Connector/Python (SQLAlchemy).
I came across with the problem:
When I try to select records form the database I get the following:
`[Wed Feb 12 09:20:34.373204 2014] [:error] [pid 29351] [remote 127.0... | 2014/02/12 | [
"https://Stackoverflow.com/questions/21721558",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2304257/"
] | I am running WIn XP WITHOUT SP3 update and this solution worked for me when using Chrome.
<http://www.technonsense.com/2014/04/chrome-ssl-error-solution/>
In short, modify your Chrome shortcut used to access the browser by appending "-ignore-certificate-errors" (without quotes) in the target field (and after "...exe"... | Double-check the actual time setting of the clock, using one of the Internet time providers. (You mentioned that you checked the time zone, but not the actual time). To do this, double-click clock, Change Date & Time, select Internet Time tab, then Change Settings, and synchronize with one of the providers listed there... |
21,721,558 | I am working on setting up the pyramid framework on python3.3 virtual env.
For the database connection I use MySQL Connector/Python (SQLAlchemy).
I came across with the problem:
When I try to select records form the database I get the following:
`[Wed Feb 12 09:20:34.373204 2014] [:error] [pid 29351] [remote 127.0... | 2014/02/12 | [
"https://Stackoverflow.com/questions/21721558",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2304257/"
] | I found a [related thread](https://productforums.google.com/forum/#!topic/chrome/5-Bf0o6YxgM) in a Google Chrome forum.
I think that the technology responsible for catching this is [HTTP Strict Transport Security](http://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security);
It looks like one of your extensions is in... | This problem happens because your system datetime is wrong. Update your window datetime correctly. |
21,721,558 | I am working on setting up the pyramid framework on python3.3 virtual env.
For the database connection I use MySQL Connector/Python (SQLAlchemy).
I came across with the problem:
When I try to select records form the database I get the following:
`[Wed Feb 12 09:20:34.373204 2014] [:error] [pid 29351] [remote 127.0... | 2014/02/12 | [
"https://Stackoverflow.com/questions/21721558",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2304257/"
] | This problem happens because your system datetime is wrong. Update your window datetime correctly. | Double-check the actual time setting of the clock, using one of the Internet time providers. (You mentioned that you checked the time zone, but not the actual time). To do this, double-click clock, Change Date & Time, select Internet Time tab, then Change Settings, and synchronize with one of the providers listed there... |
21,721,558 | I am working on setting up the pyramid framework on python3.3 virtual env.
For the database connection I use MySQL Connector/Python (SQLAlchemy).
I came across with the problem:
When I try to select records form the database I get the following:
`[Wed Feb 12 09:20:34.373204 2014] [:error] [pid 29351] [remote 127.0... | 2014/02/12 | [
"https://Stackoverflow.com/questions/21721558",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2304257/"
] | If you want to get past that just type in 'danger' in your browser. (just click on the window anywhere and type 'danger', you won't actually see the letters appear anywhere) it used to be proceed but that no longer works. | Double-check the actual time setting of the clock, using one of the Internet time providers. (You mentioned that you checked the time zone, but not the actual time). To do this, double-click clock, Change Date & Time, select Internet Time tab, then Change Settings, and synchronize with one of the providers listed there... |
21,721,558 | I am working on setting up the pyramid framework on python3.3 virtual env.
For the database connection I use MySQL Connector/Python (SQLAlchemy).
I came across with the problem:
When I try to select records form the database I get the following:
`[Wed Feb 12 09:20:34.373204 2014] [:error] [pid 29351] [remote 127.0... | 2014/02/12 | [
"https://Stackoverflow.com/questions/21721558",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2304257/"
] | If you want to get past that just type in 'danger' in your browser. (just click on the window anywhere and type 'danger', you won't actually see the letters appear anywhere) it used to be proceed but that no longer works. | I am running WIn XP WITHOUT SP3 update and this solution worked for me when using Chrome.
<http://www.technonsense.com/2014/04/chrome-ssl-error-solution/>
In short, modify your Chrome shortcut used to access the browser by appending "-ignore-certificate-errors" (without quotes) in the target field (and after "...exe"... |
71,875,058 | I have a sample spark df as below:
```
df = ([[1, 'a', 'b' , 'c'],
[1, 'b', 'c' , 'b'],
[1, 'b', 'a' , 'b'],
[2, 'c', 'a' , 'a'],
[3, 'b', 'b' , 'a']]).toDF(['id', 'field1', 'field2', 'field3'])
```
What I need next is to provide a multiple aggregations to show summary of the a, b, c values f... | 2022/04/14 | [
"https://Stackoverflow.com/questions/71875058",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16762881/"
] | Let me answer your question in two steps. First, you are wondering if it is possible to avoid hard coding all your aggregations in your attempt to compute all your aggregations. It is. I would do it like this:
```py
from pyspark.sql import functions as f
# let's assume that this is known, but we could compute it as w... | ### update
based on discussion in the comments, I think this question is a case of an [X-Y problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). The task at hand is something that is seen very frequently in the world of Data Engineering and ETL development: how to partition and then quantify... |
49,007,215 | I want get the occurrence of characters in a string, I got this code:
```
string = "Foo Fighters"
def conteo(string):
copia = ''
for i in string:
if i not in copia:
copia = copia + i
conteo = [0]*len(copia)
for i in string:
if i in copia:
conteo[copia.index(i)] =... | 2018/02/27 | [
"https://Stackoverflow.com/questions/49007215",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7590594/"
] | Depending on why you want this information, one method could be to use a `Counter`:
```
from collections import Counter
print(Counter("Foo Fighters"))
```
Of course, to create exactly the same output as requested, use itertools as well:
```
from collections import Counter
from itertools import chain
c = Counter("F... | It's not clear whether you want a critique of your current attempt or a pythonic solution. Below is one way where output is a dictionary.
```
from collections import Counter
mystr = "Foo Fighters"
c = Counter(mystr)
```
**Result**
```
Counter({' ': 1,
'F': 2,
'e': 1,
'g': 1,
'h... |
49,007,215 | I want get the occurrence of characters in a string, I got this code:
```
string = "Foo Fighters"
def conteo(string):
copia = ''
for i in string:
if i not in copia:
copia = copia + i
conteo = [0]*len(copia)
for i in string:
if i in copia:
conteo[copia.index(i)] =... | 2018/02/27 | [
"https://Stackoverflow.com/questions/49007215",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7590594/"
] | Use Python Counter (part of standard library):
```
>>> str = 'foo fighters'
>>> from collections import Counter
>>> counter = Counter(str)
Counter({'f': 2, 'o': 2, ' ': 1, 'e': 1, 'g': 1, 'i': 1, 'h': 1, 's': 1, 'r': 1, 't': 1})
>>> counter['f']
2
>>>
``` | It's not clear whether you want a critique of your current attempt or a pythonic solution. Below is one way where output is a dictionary.
```
from collections import Counter
mystr = "Foo Fighters"
c = Counter(mystr)
```
**Result**
```
Counter({' ': 1,
'F': 2,
'e': 1,
'g': 1,
'h... |
35,782,575 | I am using a python package called kRPC that requires a basic boilerplate of setup code to use in any given instance, so here's my question:
Once I create a generic *'kRPCboilerplate.py'*, where can I place it inside my Python27 directory so that I can simply type,
```
import kRPCboilerplate
```
at the beginning of... | 2016/03/03 | [
"https://Stackoverflow.com/questions/35782575",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5910286/"
] | Your module root directory is 'Python27\Lib' where Python27 is your main python folder which includes the python executable file. You can drag and drop the .py files into there and import it without any complications! | Bit late to reply, but the safest is to set a special environmental variable called PYTHONPATH which will add search location for Python to search for libraries:
eg in Linux terminal:
`export PYTHONPATH=$PYTHONPATH:/path/to/file`
note it is only the path to the file, not the filename.
If you want a more permanent so... |
50,070,398 | I am new to tensorflow. When I am using `import tensorflow.contrib.learn.python.learn` for using the DNNClassifier it is giving me an error: `module object has no attribute python`
Python version 3.4
Tensorflow 1.7.0 | 2018/04/27 | [
"https://Stackoverflow.com/questions/50070398",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5878765/"
] | You can use `transition-delay` combined with sass loops and completely avoid javascript:
```
@for $i from 0 through 3
.mobile-container.active li:nth-child(#{$i})
transition-delay: 330ms + (100ms * $i) !important
```
Check this [fork](https://codepen.io/anon/pen/aGBPXL) of your codepen. | You can use jquery plugin <https://github.com/morr/jquery.appear/> to track elements when they appear and provide data animations based on it.
E.g. You can give your element and attribute data-animated="fadeIn" and the plugin will do the rest. |
50,070,398 | I am new to tensorflow. When I am using `import tensorflow.contrib.learn.python.learn` for using the DNNClassifier it is giving me an error: `module object has no attribute python`
Python version 3.4
Tensorflow 1.7.0 | 2018/04/27 | [
"https://Stackoverflow.com/questions/50070398",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5878765/"
] | You can use `transition-delay` combined with sass loops and completely avoid javascript:
```
@for $i from 0 through 3
.mobile-container.active li:nth-child(#{$i})
transition-delay: 330ms + (100ms * $i) !important
```
Check this [fork](https://codepen.io/anon/pen/aGBPXL) of your codepen. | The fastest way is probably just to loop through each list item and create a setTimeout for a fade-in. My jquery is a little rusty but something like this:
```
$('.mobile-navigation li').each(function(index,item) {
setTimeout( function(){$(item).fadeIn();}, index*100);
});
``` |
17,903,144 | I am new in python and I am supposed to create a game where the input can only be in range of 1 and 3. (player 1, 2 , 3) and the output should be error if user input more than 3 or error if it is in string.
```
def makeTurn(player0):
ChoosePlayer= (raw_input ("Who do you want to ask? (1-3)"))
if ChoosePlayer... | 2013/07/27 | [
"https://Stackoverflow.com/questions/17903144",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2626540/"
] | `raw_input` returns a string. Thus, you're trying to do `"1" > 4`. You need to convert it to an integer by using [`int`](http://docs.python.org/2/library/functions.html#int)
If you want to catch whether the input is a number, do:
```
while True:
try:
ChoosePlayer = int(raw_input(...))
break
ex... | You have to cast your value to int using method [`int()`](http://docs.python.org/2/library/functions.html#int):
```
def makeTurn(player0):
ChoosePlayer= (raw_input ("Who do you want to ask? (1-3)"))
if int(ChoosePlayer) not in [1,2,3]:
print "Sorry! Error! Please Try Again!"
ChoosePlayer= (r... |
17,903,144 | I am new in python and I am supposed to create a game where the input can only be in range of 1 and 3. (player 1, 2 , 3) and the output should be error if user input more than 3 or error if it is in string.
```
def makeTurn(player0):
ChoosePlayer= (raw_input ("Who do you want to ask? (1-3)"))
if ChoosePlayer... | 2013/07/27 | [
"https://Stackoverflow.com/questions/17903144",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2626540/"
] | `raw_input` returns a string. Thus, you're trying to do `"1" > 4`. You need to convert it to an integer by using [`int`](http://docs.python.org/2/library/functions.html#int)
If you want to catch whether the input is a number, do:
```
while True:
try:
ChoosePlayer = int(raw_input(...))
break
ex... | You probably need to convert ChoosePlayer to an int, like:
```
ChoosePlayerInt = int(ChoosePlayer)
```
Otherwise, at least with pypy 1.9, ChoosePlayer comes back as a unicode object. |
17,903,144 | I am new in python and I am supposed to create a game where the input can only be in range of 1 and 3. (player 1, 2 , 3) and the output should be error if user input more than 3 or error if it is in string.
```
def makeTurn(player0):
ChoosePlayer= (raw_input ("Who do you want to ask? (1-3)"))
if ChoosePlayer... | 2013/07/27 | [
"https://Stackoverflow.com/questions/17903144",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2626540/"
] | You probably need to convert ChoosePlayer to an int, like:
```
ChoosePlayerInt = int(ChoosePlayer)
```
Otherwise, at least with pypy 1.9, ChoosePlayer comes back as a unicode object. | You have to cast your value to int using method [`int()`](http://docs.python.org/2/library/functions.html#int):
```
def makeTurn(player0):
ChoosePlayer= (raw_input ("Who do you want to ask? (1-3)"))
if int(ChoosePlayer) not in [1,2,3]:
print "Sorry! Error! Please Try Again!"
ChoosePlayer= (r... |
54,530,138 | I am stuck on why my code doesn't count the number of vowels, including case-insensitive, and print a sentence reporting the number of vowels found in the word 'and'.
```
import sys
vowels = sys.argv[1]
count = 0
for vowel in vowels:
if(vowel =='a' or vowel == 'e' or vowel =='i' or vowel =='o' or vowel =='u' or... | 2019/02/05 | [
"https://Stackoverflow.com/questions/54530138",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | sys.argv is a list of the running arguments, where the first element is always your running file. therefore, you do not iterate over the text but rather over the arguments ['vowel\_counter.py', 'and'].
You should do something like this:
```
vowels=sys.argv[1]
``` | The following will take care of single or multiple arguments passed in the command line. Like `python vowel_count.py foo` and `python vowel_count.py foo bar`
```
$ cat vowel_count.py
import sys
args = sys.argv[1:]
print(args)
count = 0
for arg in args: # handling multiple commandline args
for char in arg:
... |
54,530,138 | I am stuck on why my code doesn't count the number of vowels, including case-insensitive, and print a sentence reporting the number of vowels found in the word 'and'.
```
import sys
vowels = sys.argv[1]
count = 0
for vowel in vowels:
if(vowel =='a' or vowel == 'e' or vowel =='i' or vowel =='o' or vowel =='u' or... | 2019/02/05 | [
"https://Stackoverflow.com/questions/54530138",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | sys.argv is a list of the running arguments, where the first element is always your running file. therefore, you do not iterate over the text but rather over the arguments ['vowel\_counter.py', 'and'].
You should do something like this:
```
vowels=sys.argv[1]
``` | One of the major problems with your code is indentation, According to the way you've presented the code, the block that checks `count` is run on every iteration of your loop.
Secondly, you've not output the word you're checking which would have probably indicated the bug that you're reading the wrong argument. Here is... |
54,530,138 | I am stuck on why my code doesn't count the number of vowels, including case-insensitive, and print a sentence reporting the number of vowels found in the word 'and'.
```
import sys
vowels = sys.argv[1]
count = 0
for vowel in vowels:
if(vowel =='a' or vowel == 'e' or vowel =='i' or vowel =='o' or vowel =='u' or... | 2019/02/05 | [
"https://Stackoverflow.com/questions/54530138",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | One of the major problems with your code is indentation, According to the way you've presented the code, the block that checks `count` is run on every iteration of your loop.
Secondly, you've not output the word you're checking which would have probably indicated the bug that you're reading the wrong argument. Here is... | The following will take care of single or multiple arguments passed in the command line. Like `python vowel_count.py foo` and `python vowel_count.py foo bar`
```
$ cat vowel_count.py
import sys
args = sys.argv[1:]
print(args)
count = 0
for arg in args: # handling multiple commandline args
for char in arg:
... |
59,134,194 | This is a part of HTML code from following page [following page](https://orange.e-sim.org/battle.html?id=5377):
```
<div>
<div class="sidebar-labeled-information">
<span>
Economic skill:
</span>
<span>
10.646
</span>
</div>
<div class="sidebar-labeled-information">
<span>
Strength:
</span>
<s... | 2019/12/02 | [
"https://Stackoverflow.com/questions/59134194",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12460618/"
] | You need to change the format string a little and pass `width` as a keyword argument to the `format()` method:
```
width = 6
with open(out_file, 'a') as file:
file.write("{:{width}}{:{width}}\n".format('a', 'b', width=width))
```
Contents of file afterwards:
```none
a b
``` | It's a bit ugly but you can do this. Using `{{}}` you can type a literal curly brace, and by that, you can format your format string with a variable width.
```
width = 6
format_str = "{{:{}}}{{:{}}}\n".format(width, width) #This makes the string "{:width}{:width}" with a variable width.
with open(out_file, a) as fil... |
59,134,194 | This is a part of HTML code from following page [following page](https://orange.e-sim.org/battle.html?id=5377):
```
<div>
<div class="sidebar-labeled-information">
<span>
Economic skill:
</span>
<span>
10.646
</span>
</div>
<div class="sidebar-labeled-information">
<span>
Strength:
</span>
<s... | 2019/12/02 | [
"https://Stackoverflow.com/questions/59134194",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12460618/"
] | You need to change the format string a little and pass `width` as a keyword argument to the `format()` method:
```
width = 6
with open(out_file, 'a') as file:
file.write("{:{width}}{:{width}}\n".format('a', 'b', width=width))
```
Contents of file afterwards:
```none
a b
``` | I googled a little and found [this](https://stackoverflow.com/questions/36138895/how-to-set-the-spaces-in-a-string-format-in-python-3?answertab=active#tab-top). With some changes, I wrote this code which I tried and got your desired output:
```
width = 6
with open(out_file, 'a') as file:
f.write("{1:<{0}}{2}\n".fo... |
59,134,194 | This is a part of HTML code from following page [following page](https://orange.e-sim.org/battle.html?id=5377):
```
<div>
<div class="sidebar-labeled-information">
<span>
Economic skill:
</span>
<span>
10.646
</span>
</div>
<div class="sidebar-labeled-information">
<span>
Strength:
</span>
<s... | 2019/12/02 | [
"https://Stackoverflow.com/questions/59134194",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12460618/"
] | You need to change the format string a little and pass `width` as a keyword argument to the `format()` method:
```
width = 6
with open(out_file, 'a') as file:
file.write("{:{width}}{:{width}}\n".format('a', 'b', width=width))
```
Contents of file afterwards:
```none
a b
``` | A simple multiplication will work here
(multiplication operator is overloaded here)
```
width = 6
charector = ' '
with open(out_file, 'a') as file:
file.write('a' + charector * width + 'b')
``` |
54,722,251 | I am trying to connect to a mysql database (hosted on media temple) with my python script (ran locally) but I am receiving an error when I run it.
The error is:
```
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/mysql/connector/connection_cex... | 2019/02/16 | [
"https://Stackoverflow.com/questions/54722251",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1320977/"
] | make sure you've installed mysql-connector and not mysql-connector-python, to make this sure just run the following commands: `pip3 uninstall mysql-connector-python pip3 install mysql-connector` | Make sure you have given correct port number |
15,912,804 | Standard python [distutils provides a '--user' option](http://docs.python.org/2/install/index.html#alternate-installation-the-user-scheme) which lets me install a package as a limited user, like this:
```
python setup.py install --user
```
Is there an equivalent for **easy\_install** and **pip**? | 2013/04/09 | [
"https://Stackoverflow.com/questions/15912804",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/376587/"
] | For `pip`, see [User Installs](http://www.pip-installer.org/en/latest/cookbook.html#user-installs) for details, but basically, it's just what you'd expect:
```
pip install --user Foo
```
It's a bit trickier for `easy_install`. As Ned Deily points out, if you can rely on `distribute` rather than `setuptools`, and 0.6... | From the easy\_install docs
<http://peak.telecommunity.com/DevCenter/EasyInstall#downloading-and-installing-a-package>
>
> --install-dir=DIR, -d DIR Set the installation directory. It is up to you to ensure that this directory is on sys.path at runtime, and to
> use pkg\_resources.require() to enable the installed... |
15,912,804 | Standard python [distutils provides a '--user' option](http://docs.python.org/2/install/index.html#alternate-installation-the-user-scheme) which lets me install a package as a limited user, like this:
```
python setup.py install --user
```
Is there an equivalent for **easy\_install** and **pip**? | 2013/04/09 | [
"https://Stackoverflow.com/questions/15912804",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/376587/"
] | For `pip`, see [User Installs](http://www.pip-installer.org/en/latest/cookbook.html#user-installs) for details, but basically, it's just what you'd expect:
```
pip install --user Foo
```
It's a bit trickier for `easy_install`. As Ned Deily points out, if you can rely on `distribute` rather than `setuptools`, and 0.6... | I needed to do the same with my docker and deploy to AWS Elastic Beanstalk.
The issue is that **pip** and **easy\_install** (called by python setup.py) interpret the `--user` parameter in different way.
* `pip install --user PackageName` will install the PackageName to `$PYTHONUSERBASE` environment variable.
* `pytho... |
48,791,900 | I'm using the python api to upload apks, mapping files and release note texts.
See <https://developers.google.com/resources/api-libraries/documentation/androidpublisher/v2/python/latest/androidpublisher_v2.edits.html>
I'm using the `apks().upload()`, `deobfuscationfiles().upload()` and `apklistings().update()` APIs t... | 2018/02/14 | [
"https://Stackoverflow.com/questions/48791900",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/261009/"
] | You need to use the new version of Google Play Developer API v3, where you can now set "status" (completed, draft, stopped, inProgress) for Edits.tracks.
<https://developers.google.com/resources/api-libraries/documentation/androidpublisher/v3/python/latest/androidpublisher_v3.edits.tracks.html> | It isn't possible to have a manual review step at the moment. |
23,768,865 | I am trying to list some of software installed on a PC by using:
```
Get-WmiObject -Class Win32_Product |
Select-Object -Property name,version |
Where-Object {$_.name -like '*Java*'}
```
It works, but when I added more names in `Where-Object` it gave me no results neither an error.
```
Get-WmiObject -Class Win32_Pr... | 2014/05/20 | [
"https://Stackoverflow.com/questions/23768865",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3303155/"
] | I don't think `-like` will take an array on the right hand side. Try a regex instead:
```
Where-Object {$_.name -match 'Java|python|adobe|access'}
``` | The -Like operator takes a string argument (not a string array), so whatever you give it will get cast as [string]. If you cast the arguments you've give it to string:
```
[string]('*Java*','*python*','*adobe*','*access*')
```
you get:
```
*Java* *python* *adobe* *access*
```
and that's what you're trying to mat... |
60,250,462 | I have a large list that contains usernames (about 60,000 strings). Each username represents a submission. Some users have made only one submission i.e. they are **"one-time users"**, so their username appears only once in this list. Others have made multiple submission (**returning users**) so their username can appea... | 2020/02/16 | [
"https://Stackoverflow.com/questions/60250462",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5900486/"
] | You can improve by using a [Counter](https://docs.python.org/2/library/collections.html#collections.Counter), in `2.` for each element you are iterating the whole list, and you are doing this multiple times for the same user if an user occurs more than once.
Note that when you use `users.count(user)` you iterate all... | As mentioned in your own comment, Counter is significantly faster here. You can see from your own timing that creating a set of the results takes around 10ms to complete (#8->#9), which is roughly the time Counter will take as well.
With counter you look at at each of the N elements once, and then at each unique eleme... |
56,206,422 | Try to pass the dictionary into the function to print them out, but it throws error: most\_courses() takes 0 positional arguments but 1 was given
```
def most_courses(**diction):
for key, value in diction.items():
print("{} {}".format(key,value))
most_courses({'Andrew Chalkley': ['jQuery Basics', 'Node.js... | 2019/05/19 | [
"https://Stackoverflow.com/questions/56206422",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11523169/"
] | When you pass your dict as a param, you can either do it as you wrote:
```
most_courses({'Andrew Chalkley': ...
```
in this case `most_cources` should accept a "positional" param. That's why it raises: `most_courses() takes 0 positional arguments but 1 was given`.
You gave it 1 positional param, while `most_cour... | There is no reason to use `**` here. You want to pass a dict and have it processed as a dict. Just use a standard argument.
```
def most_courses(diction):
``` |
56,206,422 | Try to pass the dictionary into the function to print them out, but it throws error: most\_courses() takes 0 positional arguments but 1 was given
```
def most_courses(**diction):
for key, value in diction.items():
print("{} {}".format(key,value))
most_courses({'Andrew Chalkley': ['jQuery Basics', 'Node.js... | 2019/05/19 | [
"https://Stackoverflow.com/questions/56206422",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11523169/"
] | When you pass your dict as a param, you can either do it as you wrote:
```
most_courses({'Andrew Chalkley': ...
```
in this case `most_cources` should accept a "positional" param. That's why it raises: `most_courses() takes 0 positional arguments but 1 was given`.
You gave it 1 positional param, while `most_cour... | arguments denoted with a \*\* in the definition of a function need to be passed with a keyword:
### example:
```
def test(**diction):
print(diction)
```
Argument passed without keyword:
```
test(8)
```
>
>
> ```
> ---------------------------------------------------------------------------
> TypeError ... |
61,853,196 | I have a python file that contains these elements:
```
startaddress = 768
length = 64
subChId = 6
protection = 1
bitrate = 64
```
and I want to convert them to a single dictionary string like this:
```
{"startaddress":"768","length":"64","subChId":"6","protection":"1","bitrate":"64"}
```
so I can... | 2020/05/17 | [
"https://Stackoverflow.com/questions/61853196",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3150586/"
] | Let a package manager like [brew](https://brew.sh/) do the work for you:
```sh
brew install deno
```
Easy to install, easy to upgrade.
Check the [official repo](https://github.com/denoland/deno_install) for all the installation options. | To find the instillation options use official documentation <https://deno.land/#installation>.
For MacOS following installation options are available.
**01.Using Shell**
```
curl -fsSL https://deno.land/x/install/install.sh | sh
```
**02.Using [Homebrew](https://brew.sh/)**
```
brew install deno
```
**03.Using ... |
61,889,217 | I have this list of dictionaries.
```
[{'value': '299021.000000', 'abbrev': 'AAA'},
{'value': '299021.000000', 'abbrev': 'BBB'},
{'value': '8.597310', 'abbrev': 'CCC'}]
```
I want to transform this list to look like this;
```
[{'AAA': '299021.000000'},
{'BBB': '299021.000000'},
{'CCC': '8.597310'}]
```
Any hi... | 2020/05/19 | [
"https://Stackoverflow.com/questions/61889217",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7518091/"
] | With [list comprehension](https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions) you can do the following:
```
data = [
{'value': '299021.000000', 'abbrev': 'AAA'},
{'value': '299021.000000', 'abbrev': 'BBB'},
{'value': '8.597310', 'abbrev': 'CCC'}
]
data_2 = [{elem["abbrev"]: elem["v... | Using for loop;
```
original_list = [
{'value': '299021.000000', 'abbrev': 'AAA'},
{'value': '299021.000000', 'abbrev': 'BBB'},
{'value': '8.597310', 'abbrev': 'CCC'}
]
transformed_list = [ ]
for i in original_list:
key = i['abbrev']
value = i[... |
30,070,300 | **I want to bind two event to one ListCtrl weight in wxpython.**
**Such as, left click and right click.** The former will refresh the content of somewhere, and the later will create a PopupMenu, which contains something about rename, setting...
How should I do?
I tried `wx.EVT_LIST_ITEM_SELECTED`, `wx.EVT_LIST_COL_... | 2015/05/06 | [
"https://Stackoverflow.com/questions/30070300",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4827183/"
] | I got my Answer, it was quit simple.
Open Terminal,
Type command:
```
keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android
```
Press Enter: You will get the following info, and SHA1 can be seen there.
.....
Certificate fingerprints:
```
MD5: 79:F5:59:... | **Very easy and simply finding the SHA1 key for certificate in only android studio.**
You can use below steps:
```
A.Open Android Studio
B.Open Your Project
C.Click on Gradle (From Right Side Panel, you will see Gradle Bar)
D.Click on Refresh (Click on Refresh from Gradle Bar, you will see List Gradle scripts of yo... |
30,070,300 | **I want to bind two event to one ListCtrl weight in wxpython.**
**Such as, left click and right click.** The former will refresh the content of somewhere, and the later will create a PopupMenu, which contains something about rename, setting...
How should I do?
I tried `wx.EVT_LIST_ITEM_SELECTED`, `wx.EVT_LIST_COL_... | 2015/05/06 | [
"https://Stackoverflow.com/questions/30070300",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4827183/"
] | Type this is the Terminal
keytool -list -v -keystore ~/.android/debug.keystore
It will ask you to enter the password
enter 'android'
Then you would get the details like the SHA1. | [](https://i.stack.imgur.com/QvqG8.png)
After clicking signingReport You will get SHA-1 finger certificate for your application
I am here if you need any other help |
30,070,300 | **I want to bind two event to one ListCtrl weight in wxpython.**
**Such as, left click and right click.** The former will refresh the content of somewhere, and the later will create a PopupMenu, which contains something about rename, setting...
How should I do?
I tried `wx.EVT_LIST_ITEM_SELECTED`, `wx.EVT_LIST_COL_... | 2015/05/06 | [
"https://Stackoverflow.com/questions/30070300",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4827183/"
] | There is no way in `Android Studio` like `Eclipse` **Windows -> Preferences -> Android -> Build**.
`Android Studio` signs your app in debug mode automatically when you run or debug your project from the IDE.
You may get using the following Command!!
```
keytool -list -v -keystore ~/.android/debug.keystore
``` | Type this is the Terminal
keytool -list -v -keystore ~/.android/debug.keystore
It will ask you to enter the password
enter 'android'
Then you would get the details like the SHA1. |
30,070,300 | **I want to bind two event to one ListCtrl weight in wxpython.**
**Such as, left click and right click.** The former will refresh the content of somewhere, and the later will create a PopupMenu, which contains something about rename, setting...
How should I do?
I tried `wx.EVT_LIST_ITEM_SELECTED`, `wx.EVT_LIST_COL_... | 2015/05/06 | [
"https://Stackoverflow.com/questions/30070300",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4827183/"
] | All above answers are correct.
**But,Easiest and Faster way is below:**
1. Open Android Studio
2. Open Your Project
3. Click on Gradle (From Right Side Panel, you will see Gradle Bar)
4. Click on Refresh (Click on Refresh from Gradle Bar, you will see
List Gradle scripts of your Project)
5. Click on Your Project Name... | [](https://i.stack.imgur.com/QvqG8.png)
After clicking signingReport You will get SHA-1 finger certificate for your application
I am here if you need any other help |
30,070,300 | **I want to bind two event to one ListCtrl weight in wxpython.**
**Such as, left click and right click.** The former will refresh the content of somewhere, and the later will create a PopupMenu, which contains something about rename, setting...
How should I do?
I tried `wx.EVT_LIST_ITEM_SELECTED`, `wx.EVT_LIST_COL_... | 2015/05/06 | [
"https://Stackoverflow.com/questions/30070300",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4827183/"
] | I got my Answer, it was quit simple.
Open Terminal,
Type command:
```
keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android
```
Press Enter: You will get the following info, and SHA1 can be seen there.
.....
Certificate fingerprints:
```
MD5: 79:F5:59:... | The other way to get the SHA1 fingerprint instead of inputting a `keytool` command is to create dummy project and select the `Google Map Activity` in the `Add an activity module` and after the project is created you then open the `values->google_maps_api.xml` in that xml you'll see the SHA1 fingerprint of your android ... |
30,070,300 | **I want to bind two event to one ListCtrl weight in wxpython.**
**Such as, left click and right click.** The former will refresh the content of somewhere, and the later will create a PopupMenu, which contains something about rename, setting...
How should I do?
I tried `wx.EVT_LIST_ITEM_SELECTED`, `wx.EVT_LIST_COL_... | 2015/05/06 | [
"https://Stackoverflow.com/questions/30070300",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4827183/"
] | All above answers are correct.
**But,Easiest and Faster way is below:**
1. Open Android Studio
2. Open Your Project
3. Click on Gradle (From Right Side Panel, you will see Gradle Bar)
4. Click on Refresh (Click on Refresh from Gradle Bar, you will see
List Gradle scripts of your Project)
5. Click on Your Project Name... | Type this is the Terminal
keytool -list -v -keystore ~/.android/debug.keystore
It will ask you to enter the password
enter 'android'
Then you would get the details like the SHA1. |
30,070,300 | **I want to bind two event to one ListCtrl weight in wxpython.**
**Such as, left click and right click.** The former will refresh the content of somewhere, and the later will create a PopupMenu, which contains something about rename, setting...
How should I do?
I tried `wx.EVT_LIST_ITEM_SELECTED`, `wx.EVT_LIST_COL_... | 2015/05/06 | [
"https://Stackoverflow.com/questions/30070300",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4827183/"
] | **Very easy and simply finding the SHA1 key for certificate in only android studio.**
You can use below steps:
```
A.Open Android Studio
B.Open Your Project
C.Click on Gradle (From Right Side Panel, you will see Gradle Bar)
D.Click on Refresh (Click on Refresh from Gradle Bar, you will see List Gradle scripts of yo... | Type this is the Terminal
keytool -list -v -keystore ~/.android/debug.keystore
It will ask you to enter the password
enter 'android'
Then you would get the details like the SHA1. |
30,070,300 | **I want to bind two event to one ListCtrl weight in wxpython.**
**Such as, left click and right click.** The former will refresh the content of somewhere, and the later will create a PopupMenu, which contains something about rename, setting...
How should I do?
I tried `wx.EVT_LIST_ITEM_SELECTED`, `wx.EVT_LIST_COL_... | 2015/05/06 | [
"https://Stackoverflow.com/questions/30070300",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4827183/"
] | I got my Answer, it was quit simple.
Open Terminal,
Type command:
```
keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android
```
Press Enter: You will get the following info, and SHA1 can be seen there.
.....
Certificate fingerprints:
```
MD5: 79:F5:59:... | [](https://i.stack.imgur.com/QvqG8.png)
After clicking signingReport You will get SHA-1 finger certificate for your application
I am here if you need any other help |
30,070,300 | **I want to bind two event to one ListCtrl weight in wxpython.**
**Such as, left click and right click.** The former will refresh the content of somewhere, and the later will create a PopupMenu, which contains something about rename, setting...
How should I do?
I tried `wx.EVT_LIST_ITEM_SELECTED`, `wx.EVT_LIST_COL_... | 2015/05/06 | [
"https://Stackoverflow.com/questions/30070300",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4827183/"
] | 1. Go to your key directory / Folder.
2. Use following command in the terminal: `keytool -list -v -keystore <yourKeyFileName.withExtension> -alias <yourKeyAlias>`.
3. Enter Key Password entered at time of key creations.
**yourKeyAlias had given at time of creation of your key.** | Type this is the Terminal
keytool -list -v -keystore ~/.android/debug.keystore
It will ask you to enter the password
enter 'android'
Then you would get the details like the SHA1. |
30,070,300 | **I want to bind two event to one ListCtrl weight in wxpython.**
**Such as, left click and right click.** The former will refresh the content of somewhere, and the later will create a PopupMenu, which contains something about rename, setting...
How should I do?
I tried `wx.EVT_LIST_ITEM_SELECTED`, `wx.EVT_LIST_COL_... | 2015/05/06 | [
"https://Stackoverflow.com/questions/30070300",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4827183/"
] | Follow the below steps to get SHA1 fingerprint Certificate in Android Studio in 2.2v.
>
> Open Android Studio Open your Project Click on Gradle (From Right Side
> Panel, you will see Gradle Bar)
>
>
> Click on Refresh (Click on Refresh from Gradle Bar, you will see List
> Gradle scripts of your Project)
>
>
> Cli... | [](https://i.stack.imgur.com/QvqG8.png)
After clicking signingReport You will get SHA-1 finger certificate for your application
I am here if you need any other help |
72,304,877 | super new to python and having an error on one of my codecademy projects that i cant seem to understand, even referencing the walkthrough and altering line 17 multiple times i cant quiet understand why this is returning an error. could somebody help me understand the error so i can learn from it? this is my code thats ... | 2022/05/19 | [
"https://Stackoverflow.com/questions/72304877",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19153697/"
] | If there is only one non empty value per groups use:
```
df = df.replace('',np.nan).groupby('ID', as_index=False).first().fillna('')
```
If possible multiple values and need unique values in original order use lambda function:
```
print (df)
ID LU MA ME JE VE SA DI
0 201 B C B
1 201 C C C B... | This could be treated as a pivot. You'd need to melt the df first then pivot:
```
(df.melt(id_vars='ID')
.dropna()
.pivot(index='ID',columns='variable',values='value')
.fillna('')
.rename_axis(None, axis=1)
.reset_index()
)
``` |
2,166,818 | How do I check if an object is an instance of a [Named tuple](http://docs.python.org/dev/library/collections.html#namedtuple-factory-function-for-tuples-with-named-fields)? | 2010/01/30 | [
"https://Stackoverflow.com/questions/2166818",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/55246/"
] | Calling the *function* `collections.namedtuple` gives you a new type that's a subclass of `tuple` (and no other classes) with a member named `_fields` that's a tuple whose items are all strings. So you could check for each and every one of these things:
```
def isnamedtupleinstance(x):
t = type(x)
b = t.__base... | IMO this might be the best solution for *Python 3.6* and later.
You can set a custom `__module__` when you instantiate your namedtuple, and check for it later
```py
from collections import namedtuple
# module parameter added in python 3.6
namespace = namedtuple("namespace", "foo bar", module=__name__ + ".namespace")... |
2,166,818 | How do I check if an object is an instance of a [Named tuple](http://docs.python.org/dev/library/collections.html#namedtuple-factory-function-for-tuples-with-named-fields)? | 2010/01/30 | [
"https://Stackoverflow.com/questions/2166818",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/55246/"
] | Improving on what Lutz posted:
```
def isinstance_namedtuple(x):
return (isinstance(x, tuple) and
isinstance(getattr(x, '__dict__', None), collections.Mapping) and
getattr(x, ... | I use
```
isinstance(x, tuple) and isinstance(x.__dict__, collections.abc.Mapping)
```
which to me appears to best reflect the dictionary aspect of the nature of named tuples.
It appears robust against some conceivable future changes too and might also work with many third-party namedtuple-ish classes, if such thing... |
2,166,818 | How do I check if an object is an instance of a [Named tuple](http://docs.python.org/dev/library/collections.html#namedtuple-factory-function-for-tuples-with-named-fields)? | 2010/01/30 | [
"https://Stackoverflow.com/questions/2166818",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/55246/"
] | Calling the *function* `collections.namedtuple` gives you a new type that's a subclass of `tuple` (and no other classes) with a member named `_fields` that's a tuple whose items are all strings. So you could check for each and every one of these things:
```
def isnamedtupleinstance(x):
t = type(x)
b = t.__base... | 3.7+
```
def isinstance_namedtuple(obj) -> bool:
return (
isinstance(obj, tuple) and
hasattr(obj, '_asdict') and
hasattr(obj, '_fields')
)
``` |
2,166,818 | How do I check if an object is an instance of a [Named tuple](http://docs.python.org/dev/library/collections.html#namedtuple-factory-function-for-tuples-with-named-fields)? | 2010/01/30 | [
"https://Stackoverflow.com/questions/2166818",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/55246/"
] | Calling the *function* `collections.namedtuple` gives you a new type that's a subclass of `tuple` (and no other classes) with a member named `_fields` that's a tuple whose items are all strings. So you could check for each and every one of these things:
```
def isnamedtupleinstance(x):
t = type(x)
b = t.__base... | If you need to check before calling namedtuple specific functions on it, then just call them and catch the exception instead. That's the preferred way to do it in python. |
2,166,818 | How do I check if an object is an instance of a [Named tuple](http://docs.python.org/dev/library/collections.html#namedtuple-factory-function-for-tuples-with-named-fields)? | 2010/01/30 | [
"https://Stackoverflow.com/questions/2166818",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/55246/"
] | If you want to determine whether an object is an instance of a specific namedtuple, you can do this:
```
from collections import namedtuple
SomeThing = namedtuple('SomeThing', 'prop another_prop')
SomeOtherThing = namedtuple('SomeOtherThing', 'prop still_another_prop')
a = SomeThing(1, 2)
isinstance(a, SomeThing) ... | I use
```
isinstance(x, tuple) and isinstance(x.__dict__, collections.abc.Mapping)
```
which to me appears to best reflect the dictionary aspect of the nature of named tuples.
It appears robust against some conceivable future changes too and might also work with many third-party namedtuple-ish classes, if such thing... |
2,166,818 | How do I check if an object is an instance of a [Named tuple](http://docs.python.org/dev/library/collections.html#namedtuple-factory-function-for-tuples-with-named-fields)? | 2010/01/30 | [
"https://Stackoverflow.com/questions/2166818",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/55246/"
] | Calling the *function* `collections.namedtuple` gives you a new type that's a subclass of `tuple` (and no other classes) with a member named `_fields` that's a tuple whose items are all strings. So you could check for each and every one of these things:
```
def isnamedtupleinstance(x):
t = type(x)
b = t.__base... | Improving on what Lutz posted:
```
def isinstance_namedtuple(x):
return (isinstance(x, tuple) and
isinstance(getattr(x, '__dict__', None), collections.Mapping) and
getattr(x, ... |
2,166,818 | How do I check if an object is an instance of a [Named tuple](http://docs.python.org/dev/library/collections.html#namedtuple-factory-function-for-tuples-with-named-fields)? | 2010/01/30 | [
"https://Stackoverflow.com/questions/2166818",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/55246/"
] | 3.7+
```
def isinstance_namedtuple(obj) -> bool:
return (
isinstance(obj, tuple) and
hasattr(obj, '_asdict') and
hasattr(obj, '_fields')
)
``` | I use
```
isinstance(x, tuple) and isinstance(x.__dict__, collections.abc.Mapping)
```
which to me appears to best reflect the dictionary aspect of the nature of named tuples.
It appears robust against some conceivable future changes too and might also work with many third-party namedtuple-ish classes, if such thing... |
2,166,818 | How do I check if an object is an instance of a [Named tuple](http://docs.python.org/dev/library/collections.html#namedtuple-factory-function-for-tuples-with-named-fields)? | 2010/01/30 | [
"https://Stackoverflow.com/questions/2166818",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/55246/"
] | 3.7+
```
def isinstance_namedtuple(obj) -> bool:
return (
isinstance(obj, tuple) and
hasattr(obj, '_asdict') and
hasattr(obj, '_fields')
)
``` | Improving on what Lutz posted:
```
def isinstance_namedtuple(x):
return (isinstance(x, tuple) and
isinstance(getattr(x, '__dict__', None), collections.Mapping) and
getattr(x, ... |
2,166,818 | How do I check if an object is an instance of a [Named tuple](http://docs.python.org/dev/library/collections.html#namedtuple-factory-function-for-tuples-with-named-fields)? | 2010/01/30 | [
"https://Stackoverflow.com/questions/2166818",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/55246/"
] | If you want to determine whether an object is an instance of a specific namedtuple, you can do this:
```
from collections import namedtuple
SomeThing = namedtuple('SomeThing', 'prop another_prop')
SomeOtherThing = namedtuple('SomeOtherThing', 'prop still_another_prop')
a = SomeThing(1, 2)
isinstance(a, SomeThing) ... | Improving on what Lutz posted:
```
def isinstance_namedtuple(x):
return (isinstance(x, tuple) and
isinstance(getattr(x, '__dict__', None), collections.Mapping) and
getattr(x, ... |
2,166,818 | How do I check if an object is an instance of a [Named tuple](http://docs.python.org/dev/library/collections.html#namedtuple-factory-function-for-tuples-with-named-fields)? | 2010/01/30 | [
"https://Stackoverflow.com/questions/2166818",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/55246/"
] | If you want to determine whether an object is an instance of a specific namedtuple, you can do this:
```
from collections import namedtuple
SomeThing = namedtuple('SomeThing', 'prop another_prop')
SomeOtherThing = namedtuple('SomeOtherThing', 'prop still_another_prop')
a = SomeThing(1, 2)
isinstance(a, SomeThing) ... | If you need to check before calling namedtuple specific functions on it, then just call them and catch the exception instead. That's the preferred way to do it in python. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.