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
-
1
votes1
answer309
viewsReturn of python file read function
I did this snippet of code to read through a loop the contents of the list files. lista_nome_base_docs = ['a.txt', 'b.txt', 'c.txt'] tamanho = len(lista_nome_base_docs) print (tamanho)…
-
1
votes2
answers2142
viewsCreate list with column contents
Hello Please have a pandas.core.frame.Dataframe with these columns, in Python3: Estado 150 non-null object Cargo 150 non-null object Nome_candidato 150 non-null object CPF 150 non-null int64…
pythonasked 7 years, 1 month ago Reinaldo Chaves 333 -
1
votes1
answer391
viewsGenerate 9-digit keys with Python
I would like to generate several values following the pattern XXX-XXX-XXX where all possibilities will be generated for example: 1 - 000-000-000 2 - 000-000-001 3 - 000-000-002 . . . x - 999-999-999…
-
1
votes1
answer137
viewsScamming shorteners with python
I need for my project, some function using Python 2.7 enter a URL, and get the next URL from it. -> Example: goo.Gl/LAKFXG = / bit.ly/2D3SEnZ = / I don’t want to use the API of these URLS, but…
-
1
votes1
answer3068
views -
1
votes1
answer396
viewsWrong square parentheses (square brackets)?
I have this function in Matlab cn = reshape(repmat(sn, n_rep, 1), 1,[]); in Python I have the following code: import numpy as np from numpy.random import randint M=2 N=2*10**8 ### valor de Dados…
-
1
votes2
answers478
viewsReading list of integers from a binary file
I need to read the 10 million integer numbers that are in a binary file and put them in a list. The program does not fail, but the readings give some strange numbers: main:…
-
1
votes1
answer2225
viewsHow to check if one list is inside the other?
My code: n = [int(input()) for c in range(0, 5)] lista = list(range(0, 10)) if n not in lista: print('1') else: print('2') Digit 1, 2, 3, 4, 5 and the answer is "1", and the numbers from 1 to 5 are…
pythonasked 6 years, 11 months ago Lucas Souza 567 -
1
votes3
answers2240
viewsPython libraries to check if a number is prime
Is there any library to determine whether the number is prime or the only way is to create the program and run it normally?
-
1
votes2
answers630
viewsHow can I create sequence and math series functions in python?
How can I get the interpreter to understand what the previous value of a mathematical function is, for example: "Xn = 3.7(Xn-1)" where "n-1" means the result of the previous loop operation. Kind of…
-
1
votes2
answers195
viewsFind the problem in my Python object list
Well I’m asking this question, because I’ve tried several ways, but I can’t find the error in logic or the wrong use of some syntax in python. It would be as follows, I own this class: class…
-
1
votes2
answers168
viewsList entry with sequential search
I am trying to create a variable input function in a list that only allows entering terms not already contained in the list. I’m having trouble finding a logical solution to this, I can’t use break…
-
1
votes1
answer219
viewsDictionary and repeating structure
The problem asks me to count the size of holes in the text Exp: A, D, R, O, P has only one hole, and B has two I made the following code: qnt = int(input()) cont = 0 l = [] for i in range(qnt): txt…
-
1
votes1
answer81
viewsPython Dictionary 3
Hello, could someone help me understand why 8 is the correct answer? From now on, thank you very much.…
-
1
votes1
answer682
viewsProblem with dictionary - Attributeerror: 'int' Object has no attribute 'get'
I’m starting to learn the basics in Python, and one of the examples about dictionary lists asks for something like this: inventory = {'a' : 1 , 'b' : 6 , 'c' : 42 , 'd' : 1 , 'e' : 12} def…
-
1
votes1
answer5950
viewsbytes-like Object is required, not 'str'
I’m trying to run this code: import time import urllib.request from urllib.request import urlopen ibov = ['BBAS3.SA', 'PETR4.SA'] def yahooKeyStats(stock): try: sourceCode = urllib.request.urlopen…
-
1
votes1
answer6433
viewsPython local and global variables
I have a software that treats dates, written as follows: def EscolheDataInicio(): controle1 = None controle2 = None if controle1 == None: teste = easygui.ccbox(msg="Escolher data início?",…
python variables variable-declaration global-variablesasked 7 years, 1 month ago Bergo de Almeida 181 -
1
votes2
answers247
viewsHow to sort a list by the number of occurrences? In Python
Like, I have a list like this: lista = [1,1,2,3,3,3] And I want to order her to stay lista = [3,3,3,1,1,2] That is, the most occurring values would be at the beginning of the list, while the least…
-
1
votes2
answers649
viewsRecursion in Python 3
I’m having trouble organizing a recursive summation formula in Python. I need to calculate: My code: def seq1(n): if n == 1: return n return seq1(n-1)+(-1**(n+1)/n) I keep getting the same error for…
-
1
votes1
answer2411
viewsHow to round value created on pandas?
Hello Please, in pandas Python 3 I am creating this dataframe with the sum of another dataset: total = cand_doacoes.groupby(['CPF_candidato', 'Nome_candidato', 'Cargo']).Valor.sum().reset_index()…
-
1
votes2
answers1978
viewsHow to count the number of "Rows" in a python table
For example, I have a database called 123, in this database is the players table, which is where the players' accounts are. I want to count how many accounts there are in the database. Finally,…
-
1
votes1
answer39
viewsWindow processing of post-processing frame
It is possible to process the screen frame in Windows? I am trying to make an opensource screen color filter/compressor in python.
-
1
votes1
answer820
viewsBinary Tree with In-Order and Pre-order Path
I’m having some doubts about the route taken by this binary tree: Could you classify it as binary? Since it has 3-leaf knots?…
-
1
votes1
answer2070
viewsProgram closing immediately after opening(Post-compiled)
I’m starting to study Tkinter and compilation, and I have a basic Python notion, and I’m having some problems. Here’s an example of a basic program that, after compiling, the executable just quickly…
-
1
votes1
answer355
viewsError using socket.recv()
I am learning about python servers and I am using the socket library. But when I use the command socket.recv(1024) for the server to read what the client sent, idle gives the following error:…
-
1
votes1
answer133
viewsDefine function result return or method
Editing: A previous function generates a list like this: ['Responsável atual', 'Número do processo', 'Foro de tramitação', 'Data da intimação 05/10/2017', 'Data da ação 15/08/2011'] This is the…
-
1
votes1
answer168
viewsFunction removes chained list
Save everyone, I’m learning chained list in python, as I already have some knowledge of list in C hit me doubt about node removal, the basis of the algorithms I used in some exercises is this:…
-
1
votes1
answer1878
viewsMatrix scheduling in Python
I have problems trying to scale a matrix 5x5. First I made a null line go to the last line of the matrix (it worked out), then I tried to make a line that had the highest index be below that which…
-
1
votes1
answer220
viewsPython function in AWS Lambda
I am needing to run the following function below on AWS Lambda: def subset_sum(numbers, target, partial=[]): s = sum(partial) # check if the partial sum is equals to target if s == target:…
-
1
votes1
answer2251
viewsC pointers treated in python
#include <stdio.h> #include <stdlib.h> #include <locale.h> int main() { setlocale(LC_ALL,""); int *x,valor,y; valor = 35; x = &valor; y = *x; printf("o endereço da variavel…
-
1
votes3
answers326
viewsDoubt with variables
Hello, I have a question, it seems silly but this getting in my way, I know that in Python you do not need to add a type to variable, example: name = str("Python") but I see some people declaring…
-
1
votes1
answer466
viewsShortcut by initial letter Optionmenu in Python Tkinter
I have an Optionmenu in Tkinter in Python which is a large list, when I press the letter G for example it does not direct me to the elements with the letter G and also does not allow the use of…
-
1
votes1
answer1254
viewsAdd spaces to the end of the field - python
Hello, everybody. I have a *.txt file in which there is a column with the product code and another column with the quantity value as below: Cód. qtd 7513020087041;5.0 879705341017;24.0 11713777;8.0…
pythonasked 6 years, 10 months ago Celso Lopes 21 -
1
votes1
answer4772
viewsCreate a dictionary from a list
I have the following list: msg = ['CAD400','Uma Filial...','Solucao:','O campo...','','LIB310','A Filial...','Solucao:','Foi identificado...','Foi…
-
1
votes2
answers68
viewsExercise list ordering
Good afternoon, I am developing an exercise and in a moment I have to order a list and remove elements repeated, for this I perform the conversion to set and then convert to list again: def…
-
1
votes1
answer5780
viewsError: "Maximum recursion Depth exceeded while Calling a Python Object"
class Ponto(object): def __init__(self, x): self.x = x @property def x(self): return self.x @x.setter def x(self, valor): self.x = valor When I run the script generates: Traceback (most recent call…
-
1
votes1
answer2667
viewsHow to avoid Max retries exceeded error in scraping in Python?
In Python 3 I made a program to scrape table lines from a public website with several pages (97893). And I create a list with the rows of each column and put a sleep to try to prevent scraping from…
-
1
votes1
answer949
viewsHow to check the type of elements in a Python list?
I have a list of data, and I need to verify that all elements are integer or string, or any other type of data. It is possible to verify all elements or needs to be one by one? For example: Lista =…
-
1
votes1
answer4407
viewsHow to make a frequency distribution table in Python?
Good afternoon, One question: Could someone enlighten me on how I can make a frequency distribution table: classes; absolute and relative frequency; cumulative form; average values of each class.…
-
1
votes1
answer102
viewsHow does Python determine if a value is true?
I have the following doubt: >>> a = [200,100] >>> a[True] Exit >>> 100 >>> a = [200,100] >>> a[False] Exit >>> 200 Why does this happen? The…
-
1
votes1
answer592
viewsHow to pick a value from a certain attribute with Beautifulsoup
I’m trying to write a code that takes titles from the G1 news and prints them on the screen. The problem is that G1 uses unfinished text(...), ex: <a class=(...) title="Marcelo Bretas acolhe…
pythonasked 7 years, 1 month ago Lorran Rosa 83 -
1
votes0
answers48
viewsDoubt platform Python
I am perfecting my knowledge for the job market and decided to study the Python language and wanted to know about the market and the "advantage" of the language for which side I would focus, if I…
-
1
votes1
answer992
viewsHow to write a . csv file in Python including file settings?
How can I create a csv file containing column width information and configured header and things like that, is it possible? or we can only write the data without any configuration?
-
1
votes2
answers70
viewsGroup name into same group
I have a sales chart with sales names, products and other information imported from a spreadsheet xlsx. But it turns out that the names of the sellers appear repeated according to sales, for…
-
1
votes2
answers80
views -
1
votes1
answer270
viewsApply color palette to raw image
I have an image at gray levels and I want an algorithm to apply a color palette to it. Does anyone have a reference of an algorithm technique used or anything like that? I’m not experienced with…
-
1
votes1
answer39
viewsPython c/ swapcaser problem
The program must convert a letter in schema A->a or a->A and works normally, except that at the end of the string a None appears. Does anyone know how I can get it out? def swap_case(s): for x…
-
1
votes2
answers13897
viewsHow to remove specific position characters from a string?
I have a string read from a file that contains a data and the special new line character ' n'. Example: dado = 'teste \n' First I check the size of the string, then I can remove the last two…
-
1
votes1
answer478
viewsPassing string to team
I’m taking 2 strings in the format hh:mm:ss to then calculate the time spent between them in days, hours, minutes and seconds format. I have already split and have all fields separated into their…
-
1
votes1
answer28
viewsCross valdation n-fold
W1 W2 W3 W4 A/N 0 0.543405 0.278369 0.424518 0.844776 1 1 0.121569 0.670749 0.825853 0.136707 1 2 0.891322 0.209202 0.185328 0.108377 1 3 0.978624 0.811683 0.171941 0.816225 0 4 0.431704 0.940030…