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
-
4
votes3
answers4376
viewsCurrent date and time in time zone timestamp format
How can I print this date in timestamp format with time zone (timestampz)? from datetime import datetime, timedelta current_time = (datetime.now()) Upshot: 2019-03-28 15:14:19.108116 I would like…
-
4
votes1
answer3811
viewsHow to finish executing code in Python 3?
print('Calcula raizes equação 2º grau') a = float(input('Informe o Valor de A')) while a == 0: print('a equação não é do segundo grau') break b = float(input('Informe o Valor de B')) c =…
pythonasked 6 years, 4 months ago Antenor D. Lopes 43 -
4
votes1
answer614
viewsPrinting all attributes of a class
I have the following class: class Usuario(object): def __init__(self): self.Nome = '' self.Email = '' self.SalarioBruto = 0.0 self.SalarioLiquido = 0.0 self.Cargo = '' self.Despesas = Despesas()…
-
4
votes3
answers991
viewsShowing only pairs in the list - Python
My code needs show an int number greater than 2 and need to print the sequence of even numbers smaller than itself and need to start from scratch. If you are less than 2 have to print Invalid number…
-
4
votes2
answers1430
views.get in Python 3
Hello. I’m starting in python, and saw the following tutorial: phone_num = input("Numero De Telefone: ") Mapa_De_Digitos = { "1": "Um", "2": "Dois", "3": "Três", "4": "Quatro" } output = "" for ch…
-
4
votes2
answers2343
viewsHow to change the value of the key in a Python dictionary?
Are there any methods in Python that change the dictionary key name? I just know how to change the value. Exemplo: RE2 = { "Nome": "Leon Scott Kennedy", "Ocupação": "Oficial de Polícia (R.P.D)",…
pythonasked 5 years, 9 months ago user141036 -
4
votes1
answer1206
viewsHow to remove area of interest from the background of an image?
I am starting to work with image processing in pattern recognition, and I need to do pre-processing of the images I will use. First, I need to highlight the region of interest from the background of…
python opencv image-processing artificial-intelligenceasked 6 years, 3 months ago Tecnologia da Net 374 -
4
votes1
answer1959
viewscalculate a row-by-line list media in python
question: Using the text file notes_students.dat write a program that averages each student’s grades and prints each student’s name and average. filing cabinet: jose 10 15 20 30 40 pedro 23 16 19 22…
-
4
votes3
answers7855
viewsWhen do I use "%d" in a python language?
What is "%d" for in Python programming language?
pythonasked 5 years, 8 months ago Mikael Pereira 43 -
4
votes3
answers2125
viewsFormat Time in a Python data frame
I’m trying to format the column that brings the hours with milesimos, that is, to take milesimos and visualize hh:mm:ss only.…
-
4
votes3
answers122
viewsModule Operator invokes special object methods
To biblioteca padrão do Python has the module operator, studying the same I noticed that some of its functions have say "aliases", for example: operator.setitem(a, b, c) operator.__setitem__(a, b,…
-
4
votes1
answer516
viewsWhat does & Python mean? What is your name? is an operator?
I was looking over the loop while in Python, and everything was going well, but suddenly I see: "&", that even searching I could not find anything about. i = 0 while i < 5 : print(i) i =…
-
4
votes1
answer2305
viewsAdd new data in an empty pandas dataframe
I am creating code to read several CSV files and extract some parameters from it and assemble a new dataframe with pandas, however I am facing a problem in this construction. Initially intended to…
-
4
votes2
answers909
viewsGenerate float values between -1 and 1
I’m trying to generate values float between -1 and 1 to test if these are within the defined limits to create a vector with the amount of data that only means that I am only able to generate values…
-
4
votes2
answers528
viewsIn Python, is there any way other than `numpy` and `float('Nan')` to get the special constant`Nan`?
I’ve been reading the website of Underhanded C Contest, in which the goal is to write subtly malicious code that looks normal at first glance. One of the common techniques mentioned was the use of…
pythonasked 6 years, 2 months ago Pedro von Hertwig Batista 3,434 -
4
votes3
answers1629
viewsProblems trying to create a virtual environment with pipenv
I’m having a hard time creating a virtual environment with pipenv, I installed it without problems with the Pip, the problem happens at the time of creating the environment. I’m using Windows 10 and…
-
4
votes1
answer36
viewsSave difference between arrays in a new array
The Script below returns the intersection between arrays within a new array, I wanted to save the difference, in case what does not belong, how to modify this script ? SCRIPT: values = [] a =…
pythonasked 5 years, 5 months ago Luis Henrique 697 -
4
votes2
answers379
viewsRecover List Written in Python File
I’d like to go to my file that contains the following ['teste1', '27-12-18', '12/5/2015', 'Aberta'] ['teste2', '27-12-18', '6/7/7', 'Aberta'] ['teste3', '27-12-18', '12/5/6', 'Fechada'] and only…
-
4
votes4
answers89
viewsRepetition is not equivalent to one second
How much would be the limit value for a repeat to be compared to a second? For example: for x in range(0, 1000): print("1 segundo")
-
4
votes3
answers155
viewsWhy does print() print outputs one below the other and not the other?
Continuing my studies in Python, a new doubt arose. Before asking, I researched here on Sopt using the expression "print next to Python" and I did not find anything that could kill my doubt and…
-
4
votes2
answers1240
viewsRecursion to Python List Inversion
I’m trying to create a recursive function that reverses the order of a certain list. As a beginner, I believe I’m making mistakes during the construction of the function. def inverter(lista, size):…
-
4
votes3
answers275
viewsHow to configure pygame in English?
I’m playing a game with pygame. I want to show a text in Portuguese on the screen, but the same exchange "ç", "ã", "[", and "<" for "?" (question mark). import pygame class TelaInicial(): def…
-
4
votes1
answer1360
viewsLatitude and longitude average by CEP
I need to find the starting point and end of CEP latitude/longitude. I need to analyze on average a latitude and longitude and this initial and final parameter would show whether this coordinate is…
-
4
votes2
answers987
viewsHow to use one Model Class values in another in Django?
Talk guys, I haven’t found a north or how to research on, so I’m going to go to the O.R.. I have the following in my models.py, Ingredient and Product: class Ingrediente(models.Model): produtor =…
-
4
votes3
answers329
viewsWhy does my "Try" in Python not work?
x = int(input("Por favor, insira um número: ")) try: print(x != int) except ValueError: print("Somente números.") The mistake that gives is: ValueError: invalid literal for int() with base 10: 'x' I…
-
4
votes2
answers766
viewsIterate through multiple Xmls files with Python
Hello, everybody. Imagine the following situation: I have a directory with several Xmls Nfe files and need to move them by issuer (CNPJ) and/or issue date to another directory. I’ve been able to…
-
4
votes6
answers491
viewsOptimize code in Python
I made the code below but I have the feeling that it can be improved and that maybe I’m turning it too much. It is a code in which I have a text input and if it is not written in all uppercase…
-
4
votes3
answers289
viewsHow to print a Python operation by adding zero to the left?
a = int(input('Número: ')) b = int(input('Número: ')) c = a / b print(c) If I assign A = 10; B = 5 print will show 2, I wonder if there is some kind of format that allows print to show 02? Thank…
pythonasked 4 years, 10 months ago Eduardo Carlos Santos Pereira 41 -
4
votes3
answers11645
viewsUsing Groupby in Pandas dataframe
good afternoon. I don’t have much skill with Python, I’m having some doubts. Anyone who can help me, I thank you. I opened my csv file in python as follows: import pandas as pd caminhoArquivo =…
-
4
votes1
answer514
viewsHow to write a __init__ file in Python 3?
I created a directory with 3 modules. As below: operacoes __init__.py soma.py media.py In my file __init__.py I have the following code: from media import * The module soma.py is used within the…
-
4
votes3
answers1145
viewsHow to remove spaces from a string in Python without also removing line breaks?
I need to remove unnecessary spaces from the strings, but not the break between the lines. I have used the command below, which removes the spaces, but also removes the break with the /n. Does…
-
4
votes1
answer888
viewsRegister different types of users in Django admin
I have three types of users: Manager, Teacher and Student. All of them need to log into the system, but the teacher and student have some more information. The manager who creates access for the…
-
4
votes1
answer111
viewsHow to see the weights in Tensorflow?
I made a neural network to estimate a final value for myself, based on 7 inputs. It has only one hidden_layer with 95 perceptrons. I’d like to see what weights are used after training. I’ve searched…
-
4
votes2
answers213
viewsDeath Note in Python - Loop Sentinel of Death
I have a question in my code of Death Note where I can’t create a loop to ask if the notebook user wants to kill someone else and the code should be closed when the user no longer wants to kill…
pythonasked 5 years, 9 months ago user141036 -
4
votes3
answers176
viewsDoubt exercise with lists
Follow the problem: Create a Python function that takes a list and returns how many numbers are positive. If a list element is not an integer or real number (float), the function must stop and…
-
4
votes1
answer2163
viewsHow to compare elements of the same index in a list
I have the following problem to solve: Consider that Mariazinha has performed a multiple choice approval. We now want to determine the number of hits Mariazinha. To this end, the template and…
pythonasked 5 years, 8 months ago Diovana Valim 203 -
4
votes1
answer351
viewsMerge the contents of two lists by considering the contents in Python?
The scenario is this, I have two lists, ex: list1 = [1,2,3,4] list2 = [5,6,7,8] I want to generate a new list that looks like this: [15,26,37,48] That is, to "join" the elements of each index. I did…
-
4
votes1
answer1967
viewsHow to take data from a JSON with Python
I’m taking data from a JSON. Only I’m having a problem. { "atividade_principal":[ { "text":"Atividades de televisão aberta", "code":"60.21-7-00" } ], "data_situacao":"03/11/2005", "nome":"GLOBO…
-
4
votes0
answers134
viewsHow to solve the Delaunay triangulation problem?
I have a problem involving Delaunay triangulation. I need to perform a triangulation of some circles. However, I need to remove some triangles that are invalid for me, because the triangulation is…
-
4
votes1
answer799
viewsHow to export classes, methods or constants in a Python module
Hello, I’m starting to work with Python and have a good experience with Typescript. In Typescript, I have a habit of creating modules when I need to organize my code, so: <rootDir> domain…
-
4
votes1
answer137
viewsHow to create a regex equivalent to a BNF?
I need to create a regular expression that is equivalent to the following BNF: <SEQ> ::= <DIG><SEQ> | <DIG> <DIG> ::= 0|1 I tried to create a Python code with the regex…
-
4
votes1
answer112
viewsWhy does Python have such big numbers?
What would be the largest number in python? Python shows the result of expressions like: >>> 8**150000 The result was 135465 digits! I wanted to know the language can do this.…
-
4
votes1
answer6370
viewsHow to configure the Vscode terminal?
I am trying to configure my Vscode so that I can install libraries through the integrated terminal but I am having problems, it seems that Vscode does not "synchronize" with the standard terminal.…
-
4
votes4
answers412
viewsHow to check if a list contains 3 consecutive numbers
Insert a vector with 10 random integer values. Then check if there is a sequence of 3 consecutive numbers in the vector. Two values are consecutive if the difference is 1 unit example: A = [10, 5,…
-
4
votes1
answer129
viewsDoubt how to display the name of a dictionary key
It is possible to display the name of only one key of a dictionary? ex: notas_por_materias = { "Matematica" : 7, "Portugues" : 8, "Historia" : 10 } I can display a print showing the subject name and…
-
4
votes2
answers242
viewsProblems with python code
I am practicing Tkinter and what I want is to create a button where the user chooses an image and then pass this image to perform another function with opencv. But when executing the code, the…
-
4
votes2
answers95
viewsRemove specific set from the end of the regex array
GOAL I am trying to remove all elements of the array from the contents ":PM" with regex, but is returning me error. DETAILS The array will always contain ":PM", and it is only this part that I wish…
-
4
votes1
answer3554
viewsHow to make a Bruteforce in Python?
I’m trying to create a Bruteforce program that can generate passwords with a size x of characters. The problem is that I can’t develop a logic for this. See my code below: chars = getAllChars() #…
-
4
votes1
answer71
viewsWhat does Typevar’s covariant and contravariant of the Typing module mean?
When using the module typing Python, available in 3.5+ versions, it is possible to define new types using the structure TypeVar. from typing import TypeVar T = TypeVar('T') # Pode ser qualquer tipo…
-
4
votes4
answers200
viewsFind character succeeded by another character using Regex
I am trying to assemble a regular expression that can identify and correct an invalid JSON. What I am trying to do specifically is the following, using as an example the following JSON: { "array":…