Most voted "python" questions
Python is a dynamic and heavily typed programming language whose design philosophy emphasizes usability. Two similar but incompatible versions of Python are in use (2 and 3). Please mention the version you are using when asking a question about Python.
Learn more…8,642 questions
Sort by count of
-
5
votes3
answers139
viewsLists within lists: Even when sliced, there is connection between lists
I’m studying lists and there’s a behavior I don’t understand. I know that when I equate one list with another, a connection between them is created. And that when I slice a list, I create a copy of…
-
5
votes2
answers1359
viewsShould I commit my virtualenv to Github?
I did a project in Python using a virtualenv, in this case I should upload all virtualenv to Github or just the Python code?
-
5
votes1
answer490
viewsStereo camera calibration via openCV chessboard
I am trying to calibrate a stereo camera using openCV, but the function findChessboardCorners is always returning False, I believe it is in function of high image distortion. Any hint of…
-
5
votes1
answer247
viewsRemove eye shine on image
Well, I’m trying to apply Canny edge to the image but the brightness that is contained in the pupil hinders the result because to have an edge with cv2.Canny() or feature.canny() needs there to be a…
-
5
votes2
answers2447
viewsHow to automatically download PDF to Selenium? With Python
I am using Python with the Selenium webdriver to automate the download of multiple PDF files. I get the PDF preview window. And now I would like to automatically download the file without popping up…
-
5
votes1
answer1933
viewsSwap String part in all dataframe columns
I have a dataframe in the following template: lista = [] lista.append(['A1','2','A3']) lista.append(['4','A5','6']) lista.append(['A7','8','9']) df = pd.DataFrame(lista, columns=['A', 'B', 'C']) df:…
-
5
votes3
answers150
viewsTwo equal programs providing different outputs
I’m developing a program that’s one of those classic programming exercises that involves the Fibonacci sequence. The program is simple, it asks the user to enter a term of the sequence and the…
-
5
votes0
answers48
viewsUse of Else outside an if
I was writing a program that would give me all prime numbers between 1 and a certain number that should be informed by the user. After several adjustments to the code, I came to the following final…
-
5
votes3
answers144
viewsIs there any way to pass the parameters to a constant function?
I’m trying to do the following, I have this connection to Influxdb: InfluxDBClient('localhost', 8086, 'root', 'root', 'example') But I want to turn these parameters into a constant, so I don’t have…
-
5
votes1
answer178
viewsWhat is Lazy, Laziness in Python/Django?
I’m starting to program and reading the documentation from Django, I saw some references about lazyObject, about Django being Lazy and that Querysets sane Lazy. I’ve done some research but I haven’t…
-
5
votes1
answer73
viewsscrape news portal comments
am programming enthusiast. am trying to scrape comments from a news portal to make a cloud tag. I’m trying to do this using Beautiful Soap but have gotten a None return. Follow the code I’m using.…
-
5
votes1
answer239
viewsWhere are the objects created in Python stored?
I made a little script to record student data where I work. I can instantiate it and I can see the data right after. But, after leaving the program, this data is lost. Are these objects only stored…
-
5
votes2
answers675
viewsWhat is RDD (resilient Distributed dataset)?
I’m studying about Spark in Python and the acronym RDD always appears. However I can’t understand what this nomenclature is really about. So I’d like to know what it is resilient Distributed dataset…
-
5
votes3
answers896
viewsHow to insert a character in the middle of the sentence
I am implementing a function that checks whether within a word there are two equal letters in a row, and if so, add an x between the two letters to separate them. Example: Entree: pizza Exit: pizxza…
-
5
votes1
answer113
viewsWhat is the best way to use threading in this example?
That is the challenge: Create a function that shows an item from a list every second. Using threads, make the program show all items as quickly as possible My code: import threading import time…
-
5
votes4
answers1335
viewsHow to use . replace() to remove Python strings
I’m doing a Coursera exercise in Python. In this exercise he asks to build a Python function that takes a string (word) and removes the punctuation symbols. It provides me a list of strings ["'",…
-
5
votes2
answers441
viewsCheck if a string belongs to a list
This program is only printing that the letter entered by the user is a consonant, even when it is a vowel. I think it has to do with the in and not in, but I’m not sure. mensagem= list (input…
-
5
votes2
answers181
viewsSimple ways to break a *while* with a function
I usually run into this problem: while True: input_chute = int(input("chute: ")) if input_chute == 0: break bla bla bla ... In that example above I break while with a condition and a break, however,…
-
5
votes1
answer742
viewsHow does Python manage memory when assigning different types?
I wanted to understand how dynamic typing is done. In Python, for example, when we create a variable with content a number int and then that same variable gets a string, the fact of not giving…
-
5
votes2
answers328
viewsPrint multiple numbers with a separator between them, but do not put the separator after the last
Make a program that reads two integers, representing the start and end values of a range and print the multiples of 5 between them. My code: valores = input().split() numero1 = int(valores[0])…
-
5
votes3
answers195
viewsList without negative number
The exercise is as follows: a program that reads the values and separates them into a list of pairs or odd numbers. The count only stops when a negative number comes (which should not be on the…
-
5
votes3
answers515
viewsSum of factorial in a specific range
I need to add the factors from 1 to 10, but I have not found the best way to implement this function. def soma_fatorial(): resultado = 1 for i in range(1, 11): resultado = resultado * i return…
pythonasked 4 years, 3 months ago Marco Raad 43 -
5
votes2
answers238
viewsPython dictionary and functions
I don’t understand why the following code says that it is receiving more than one pro value same parameter. def foo(name, **kwds): return 'name' in kwds foo(1, **{'name' : 2})´ Typeerror: foo() got…
-
5
votes1
answer269
viewsHow to improve/optimize a color image conversion code to grayscale
I am testing turn a black and white image on the nail and managed using the following code. import cv2 imagem = cv2.imread("goku-jr.jpg") for coluna in imagem: for pixel in coluna: media =…
pythonasked 5 years, 5 months ago LucasElias 83 -
5
votes1
answer54
viewsMatch between dictonary and array
GOAL: I’m trying to match one dictonary and a array. I want to check if the contents of the array are contained in KEY NAME dictonary, if it is it should return me the whole line of dictonary.…
-
5
votes2
answers260
viewsIn Python, how do you remove specific characters from all the records of just one particular column?
I’m at Jupyter Notebook working with Python. The dataframe has some columns, but in a specific column I want to delete all records that end with ". txt", meaning the last 4 characters. Image of the…
-
5
votes3
answers110
viewsHow to "flatten" a list of lists of integers?
I have a list of lists d = [[1],[2],[3],[3]] And I’d like to turn it into a list s = [1,2,3,3] I don’t really understand the difference between d and s, but I need to do the transformation because I…
-
5
votes1
answer60
viewsWhy can’t Ambroses support type notes?
We know that Python, as of version 3.6, supports annotating types in functions and variables, according to the PEP 526 -- Syntax for Variable Annotations and PEP 3107 -- Function Annotations. def…
-
5
votes1
answer104
viewsIs it recommended to explain all variables?
This is a question as to the readability of the code or if there is any style pattern as to this. Well, the Zen of Python tells us that Explicit is Better than implicit. but how to interpret this?…
-
5
votes2
answers143
viewsRandom Hoice and shuffle with different behaviors
I’m testing some codes with the module random and I noticed a difference in behavior between random.choice() and random.shuffle(). Following the codes I’m training: import random alunos =…
-
5
votes0
answers345
viewsAPI googletrans mistranslating texts
I am trying to create a Python application where I need to translate some texts, and to perform such a task, I am using the API googletrans. text = 'Back in the day people used to go to many…
-
5
votes1
answer1155
viewsGet the smallest positive number that is divisible by all numbers from 1 to 20
I made a code in a way that works, but it doesn’t look anything pythonic, and takes a lot of time. i = 1 numero = 1 while i != 0: if numero % 1 == 0 and numero % 2 == 0 and numero % 3 == 0 and…
-
5
votes1
answer95
viewsGet equivalent expression to list(zip(list, Heights)) using the map() function
Be: heights = [x*0.0254 for x in [69,77,54]] lista = [69,77,54] The expression: print(list(zip(lista,heights))) has as output: [(69, 1.7526), (77, 1.9558), (54, 1.3716)] My goal is to get the same…
-
5
votes2
answers74
viewsWhat it really means "from modulox import *"
As far as I know it matters all the classes and functions of a certain file without having to reference it in the code, right? But I’m beginning to think from modulo import * doesn’t mean that. I…
-
5
votes2
answers46
viewsInterpretation of Dive into Python on exceptions
Here is an excerpt from page 47 of the book 'Dive Into Python' about exceptions: "...You don’t need to Handle an Exception in the Function that raises it. If one Function doesn’t Handle it, the…
-
5
votes1
answer140
viewsHow to make the ":. 0f" format not round my number
I wanted to know how I use the format ":.0f" without rounding up the number. I want to catch a input of seconds and turn it into minutes, here’s my code: segundos = int(input()) minutos = segundos…
-
5
votes3
answers203
viewsShould I always use Try catch to fix mistakes?
Sometimes when I know something may fail in my system I do a validation using if, equal is below: lista = [1,2,3] #um número que esteja entre os indices da lista numero = int(input(f'Digite um…
-
5
votes2
answers197
views"List Comprehensions" is it worth it?
Is the use of List "Comprehensions" in Python a good use? Affects program performance (runtime, etc..)? Some examples: # Lista com números pares de 0 a 10: par = [x for x in range(11) if x % 2 == 0]…
-
5
votes1
answer236
viewsWhat do you mean, "Empty Dataframe"?
I’m learning and doing a lesson from my college. My teacher asked to use format table filters .csv using the command .query() So original is like this: Funcionario Escolaridade Genero Idade Meses…
-
5
votes2
answers81
viewsCompare two lists without interference of upper and lower case letters
I want to develop a log-in system where it does not allow new users to have the same names already used by other registered users, but I’m having a problem in case of upper and lower case letters…
-
5
votes1
answer90
viewsHow to use Beautifulsoup’s "find" to find a script tag with a specific type?
For a while I have been studying how to use Beautifulsoup to be able to find tag content etc. But I came across a problem where the content I want to find is inside a tag <script…
-
5
votes3
answers211
viewsProblem where IF and ELIF do not work in Python
First time programming, I started a week ago and I gave up trying something. However, I have a problem where, no matter what I put in the variable, it always shows the same result, which in the case…
-
4
votes2
answers1015
viewsHow to make a request by sending cookie data?
I want to file a requisition GET for a particular URL, but I want to send cookie data, as a web browser does. For example, in the code below: from urllib import request req =…
-
4
votes1
answer648
viewsHow to convert screen coordinates to Cartesian coordinates?
In Python: How to convert screen coordinates to cartesian coordinates, where there can be positive and negative points and the center of the screen is (0.0)?
-
4
votes2
answers2696
viewsHow to run a subprocess with admin permission?
I’m making a script that accesses the cmd windows, via subprocess. Only I need to rotate the cmd as an administrator. The solution I found, does not satisfy me, which would be to use the runas. What…
-
4
votes1
answer877
viewsInput in Sublime Text
I am using Sublime Text to study python, but it does not support input. When running the following code with the sublime build: velocidade = int(input("Digite a velocidade: ")) I get the following…
-
4
votes1
answer4059
viewsHow to run the current line in Sublime Text 2? Or, IDE that allows running the current line in Python
In the rstudio (IDE to r) it is possible to run the current line instead of the entire file using ctrl (or cmd) + enter. This is very useful for when you want to test just one piece of code separate…
-
4
votes2
answers666
viewsView in Django does not return Httpresponse object
I am doing a simple CRUD in Django for learning purposes. However, I am having a problem. When creating a view to add data to a schedule, the server returns the following error: The view…
-
4
votes1
answer3300
viewsStatic variable in Python
I came from Java. I have a variable in a class that I need to change in more than one method. I tried to put it global, but it consumes a lot of resource. How to implement this? It would be the same…
-
4
votes3
answers8766
viewsRead a few lines from a file
I have a file with about 3 million lines. I have to read line by line and process some modifications, and after these modifications in line store the result in a list to then write to another file.…
pythonasked 10 years, 9 months ago Cristiano Pires 119