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
-
3
votes3
answers351
viewsHow to access the key, by value, in python dictionary?
When filling in the name of 10 people and their respective heights, I need to show on the screen the name of the tallest person. However, I can only get the highest value. Could someone help me?…
-
3
votes3
answers529
viewsProduct between scalar and array
I have a vector: a = [0.4850045, 0.45512111] and a vector of an element: b = [-0.03116616] I’m trying to multiply the vector content b, that is to say, b[0], by vector a, but instead of getting :…
-
3
votes2
answers275
viewsHow to write a program that fills a 10-position vector with random integers between 0 and 20?
How do I create a vector v of 10 random elements in which each element is one whole between 0 and 20? I tried to use the function np.random.random((1,10)), but the output was a vector of decimal…
-
3
votes1
answer403
viewsftplib and pyftpdlib communication
I have a server (Fedora 29) at home running (as root) an ftp done in python with the ports 5000-5003 and 40000-50000 open, the machine is in DMZ import logging import sys from pyftpdlib.handlers…
-
3
votes1
answer80
viewsInteger variable that controls the loop
I’m asking the fifth question of this exercise: Question 5: Given a list of ints, Return True if first and last number of a list is same The code is down. In it, while the user type an integer other…
pythonasked 5 years, 4 months ago roger roger 124 -
3
votes1
answer762
viewsImplement Thread in Python
Following the theory of this question and answer I understood that I can run more than one program, right? I have a database with more than 3,000 users to check, this check works as follows, it…
-
3
votes1
answer62
viewsFill date.frame using for output
I wanted to know how to apply the logic of R to Python. For example: If I enter the code below in R: x <- data.frame() for (i in 1:10) { x[i,1] <- i } It will create in the date.frame x a…
-
3
votes1
answer1112
viewsCount number of unique records in a Data Frame
I have a base with a column custumer_id and I need to know the amount of unique records on the base. quantidade_clientes = df[['customer_id']] quantidade_clientes.count() This way I count everyone,…
-
3
votes1
answer129
viewsConcatenate large python csv files
I am trying to concatenate files that reach a sum of 650MB, and is returning memory error: > MemoryError: Unable to allocate 70.3 MiB for an array with shape (3, 6143249) and data type object…
-
3
votes2
answers242
viewsWhat is virtualenv for in Python?
What is virtualenv for in Python? Do you have any alternative to non-use or is it more advisable to use it?
-
3
votes2
answers62
viewsPython 3: How to recover key names after a Sorted
Hello someone can help me recover values from that dictionary list? sellers = [ {"name": "Joaquina", "store": 2, "value": 1200.00}, {"name": "Pedro", "store": 2, "value": 120.00}, {"name": "Maria",…
pythonasked 5 years, 3 months ago Margot Paon Garcia 33 -
3
votes3
answers171
viewsDoes the function not return the minimum value?
Make a Python function call min_max(t), which receives a list of numbers, and returns another list containing respectively the lowest and highest value of the original list. Follow the code so far:…
-
3
votes2
answers277
viewsHow to capture a number in a string using regular expressions (or similar method) in Python?
I would like to know how I can select a specific part of my text considering that this part refers to a value that can change. For example, the string: # 44,739 % of all cache refs I would like to…
-
3
votes1
answer207
viewsHow to plot a graph in python using a file containing numpy arrays?
Good afternoon! I am creating a python program that plots the graph of the quadratic function (y=x**2), however, you need to put the data of x and y in a file and plot the graph by extracting the…
-
3
votes1
answer157
viewsWhat is the difference between string find and index methods in Python?
I always use the method index to fetch the index of a character in a string in Python. I recently discovered the method find() and I noticed that he does exactly the same thing. Example: name="Alan…
-
3
votes1
answer97
viewsList exiting order while looping
The script below captures the INTERFACE network of a HOST, and inserts into the database (POSTGRES), I swapped the cursor method for a print to check how it was being inserted into the database, and…
-
3
votes2
answers141
viewsProblem in Python3
Hello, I’m (very) new to Python and would like to know what’s wrong with my simple code (to learn Python): eleitores = (int(input('Digite o total de eleitores: '))) c = 0 cand_a = 0 cand_b = 0…
-
3
votes2
answers536
viewsAdd values between ICT
GOAL: I am trying to add the values between Dict ct_db and ct_db2, whenever the keys are equal. Example: RR-00 == RR-00, so make 14 + 223 Problem: It is not being compared all Dict keys, the…
-
3
votes4
answers167
viewsHow to return the first vowel of several words in a list?
The code is partially done, but it returns only the vowels found in each word. How could I return only the first vowel of each word? palavras = ('boi', 'vaca', 'macaco', 'ovelha', 'lesma',) vogais =…
-
3
votes1
answer39
viewsregex python delete all after the second occurrence of a whitespace
That should be very simple and I can’t find an answer. I have several strings of different sizes that have more or less the same pattern: 'Art. 1° E' 'Art. 15. As' What I want to do is delete…
-
3
votes2
answers85
viewsFormatting to number of decimals dynamically using Python
import math def formating_pi(n): a= "pi com {:c} casas decimais é {:.17}" return a.format(n, math.pi) formating_pi(5) I’d like to not put the number 17 explicitly, but rather the result of the…
-
3
votes1
answer358
viewsEncoding error (Non-utf-8 code) while running script
I made a very simple program, this way, in the notebook, and saved how Somador.py: a = 1 b = 1 soma = a + b print("A soma dos números é", soma) After that I tried to run the program by cmd and gave…
-
3
votes3
answers114
viewsReading undesirable characters - Python
A way to separate words from a string provided as in the method below: entrada = input().split(" ") Doubt: If I want to exclude more than one specific character (" ,&ˆ*!!:") not necessarily in…
-
3
votes1
answer56
viewsHow to write tests for an External API call?
I am researching about Unit Testing and TDD and wanted to apply this to some scripts I have developed. The issue is that these scripts create data on an external service by calling API methods, for…
-
3
votes3
answers220
viewsHow to popular a dynamically key and value dictionary?
Write a program that takes an integer n value and returns a dictionary where the keys are numbers from 1 to n and the values are the squares of their respective keys. Ex: for n = 8, the result…
-
3
votes1
answer122
viewsNeed to use @classmethod in __new__
I was reading about __new__ in the Python documentation and after search here on the site I saw some examples of implementation and noticed that the signature of the method is: def __new__(cls,…
python python-3.x characteristic-language objects metaclassasked 5 years, 1 month ago fernandosavio 9,013 -
3
votes1
answer54
viewsTkinter - set master in another script
I am creating a GUI with Tkinter and I am having problems separating functions from the main file (as it is getting too big). I created a new function file, when I try to import the creative…
-
3
votes2
answers402
viewsChanging lines of an array - Python Pandas
I have an array and need to change the order of the lines. array([[ 0, 1, 2, 3, 4], [ 5, 6, 7, 8, 9], [10, 11, 12, 13, 14], [15, 16, 17, 18, 19], [20, 21, 22, 23, 24]]) I need it like this: array([[…
-
3
votes0
answers40
viewsCreate lines from the index of a Python series or dataframe
I created this dataframe: x = [1,3,5,8,10,15,4,5,6,8,23,12,28] x = pd.DataFrame(x) I created the following dataframe: I created a new dataframe with the following code: z = [] for i in…
-
3
votes1
answer172
viewsWhat is the breakpoint function for
I’m digging myself in python, and as a good curious beginner I am researching the functions already present in the python without the use of any library, when I come across the function…
-
3
votes1
answer97
viewsHow to compare two string values with pandas?
Hello! I have two pandas dataframes and selected a column of each with ids. I want to compare the ids to see if the id of one dataframe is contained in another, but it does not have the same amount…
-
3
votes1
answer303
viewsWhat is the difference between Random.Choice and Random.Choices in Python?
I know they both draw random numbers, but what’s the difference between them ?
-
3
votes1
answer64
viewsWhat is the best way to check if a string has any of these words?
I have a question, consider the following: nomes_proibidos = ['Corona', 'Clorivaldo', 'Pfizernaldo', 'Hulk', 'Naruto', 'Goku', 'Cloroquina'] def verificar_nome(n): for nome in nomes_proibidos: if…
-
3
votes2
answers807
viewsCounting frequencies in a list
I have the code below that works to count frequencies in a list. However, the output of this code is a NoneType and so I can’t use methods like .sort(), for example, to arrange the output to show in…
-
3
votes1
answer62
viewsHow long does Developer lru_cache live?
I’m developing a Python script that needs to memorize the information (possibly a cache) of previous instances and I ended up finding the developer @functools.lru_cache, but I was left with doubts…
-
3
votes1
answer158
viewsMatrix Loop with multiple vectors: Pyhton
Good evening, everyone I’m a beginner in Python and I would like your help, I did this program but the answer is in the form of several vectors or 24 vectors, and in reality I wanted only a…
-
3
votes2
answers3755
viewsOpen new tab using Selenium and python
I’ve tried everything. Here’s the thing. I open a page using selenium and the python language, then I try to open a new tab, and then go to that new tab, then close this tab. That’s it. But in…
pythonasked 5 years ago André Oliveira 43 -
3
votes1
answer1343
viewsThe Truth value of a Series is ambiguous. Use a.Empty, a.bool(), a.item(), a.any() or a.all()
I am a layperson in programming, in the stackoverflow community and I am not able to solve the following problem: Create two lists (or if you prefer 2 columns in a New Dataframe) in which you search…
-
3
votes1
answer97
viewsHow to make a list of recursive iterations - Python
I am implementing a python Hanoi tower and I need a log of all moves. It could be a list of the states of the 3 stacks. But when I try to use the append function for this list/log, the result is the…
-
3
votes2
answers57
viewsInput resulting in None
I was trying a new to present the texts in a basic game that I’m creating, which basically gives a sense that the text is being written The code is this below: def print_slow(txt): for x in txt:…
pythonasked 4 years, 11 months ago Wilson Bonato 45 -
3
votes2
answers65
viewsDelete prepositions and text articles in python
I imported a file to Python where I recognized all the words and I need to get the frequency they appear in this text, but the highest frequencies are prepositions (from, to, with) and articles (a,…
pythonasked 3 years, 3 months ago Luiz Eduardo 41 -
3
votes2
answers83
viewsGrab last file that entered in "Downloads" folder
How can I open the last file that was downloaded in the folder "Downloads" with Python? I saw several options with the libs os.path and os.walk but none of them makes it possible to take the last…
-
3
votes2
answers183
viewsHow to check if the entered option is among the valid options
I’m doing Exercise 28 of the website’s Decision Structure list [Pythonbrasil] (https://wiki.python.org.br/EstruturaDeDecisao) but when I include the code for when the user chooses an invalid option…
-
3
votes1
answer365
viewsWhat is the right way to perform performance tests in Python?
In answering that question Python syntax both accepts "+" and "," in the "print" command()"? : I submitted the following reply: Caso sua intenção seja imprimir apenas uma linha, ambos os métodos não…
pythonasked 4 years, 10 months ago Augusto Vasques 15,321 -
3
votes2
answers145
viewsRecursive method to display the representation of an integer in a base
Write a recursive method base() which accepts a non-negative integer n and a positive whole 1 < b < 10 and present the basic representation b of the whole n. >>> base(0, 2) 0…
-
3
votes1
answer158
viewsFind differences between arrays, with probability of variation
Good afternoon guys, I’m reading about the numpy library setdiff1d function (https://docs.scipy.org/doc/numpy/reference/generated/numpy.setdiff1d.html). It basically serves to express the different…
-
3
votes2
answers420
viewsRegular expression that recognizes Portuguese words (accented) using Python
Develop the function frequency(), that takes a string as input, calculates the frequency of each word in the string and returns a dictionary that maps words in the string at its frequency. You must…
-
3
votes1
answer86
viewsIs it correct to use a static method of an abstract class?
During a work assignment I came across the need to use an abstract class method to avoid code duplication. In this case, I came to a question whether it is correct to use a method of a class, which…
-
3
votes2
answers301
viewspython np.Where with two conditions
Hello, I have the following dataframe: import pandas as pd import numpy as np x = pd.DataFrame({'A': [1,2,3,0], 'B': [5,0,0,1]}) What I want is to create a column’D', which is True if the two…
-
3
votes1
answer77
viewsCopy and split a List in Python3, Merge Sort
I was trying to write the merge sort in python on my own, but returned a list nothing to do with several repeated numbers. When checking the solution code online, I was left with doubts about how to…