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
-
8
votes4
answers10409
viewsHow do you display "Press ENTER to continue" in Python 3.4?
I wanted to know how to do the " Press ENTER to continue", or the "Press any key to continue" in Python 3.4, without having to create a single variable to store ENTER.
-
8
votes2
answers1745
viewsThreads in python 3.4
Well, I have a certain difficulty in using threads, I need to perform the following procedure: I have several items to be compared with a variable, but this comparison takes a certain amount of…
-
8
votes2
answers15912
viewsHow do I join a list in Python?
When I want to unite a array in PHP, I use the function array_merge Thus: $a = [1, 2, 3]; $b = [4, 5, 6]; array_merge($a, $b); Upshot: [1, 2, 3, 4, 5, 6] And how could I do that in Python in a list…
-
8
votes2
answers878
viewsWhen to use list comprehension and not filter+lambda?
Good night, you guys. Studying here, I found the functions of List Comprehension and filter+lambda, but both seemed very similar to me on some points... When should I wear List Comprehension instead…
-
8
votes2
answers2267
viewsWhat is the __init__.py file for in python modules?
I’m starting to work deeper with Python and have noticed many projects with files __int__.py in folders, and are often blank. What is the purpose of these files?
pythonasked 9 years ago Leo Ribeiro 581 -
8
votes1
answer451
viewsIn Python 2 is it more performative to use range or xrange?
The programming language I use the most is PHP :( and, after it has been implemented Generators in version 5.5, it is said to be faster to use it for generating numbers in sequence than with the…
pythonasked 8 years, 11 months ago Wallace Maxters 102,340 -
8
votes2
answers16188
viewsHow to compare two lists in Python?
I have two lists whose contents refer to a arquivo1.txt and the other one arquivo2.txt, there are differences in the contents of the files and wish to search only the data that is in file2.txt and…
-
8
votes2
answers17548
viewsInput or raw_input?
Can anyone tell me the difference between input and raw_input in Python and how to use both?
pythonasked 8 years, 7 months ago Rubem Nanclarez 81 -
8
votes1
answer2888
viewsWhat is the purpose of virtualenv and why not install globally?
I saw that the VirtualEnv provides a way to create different environments for application development in Python. And, whenever we use, it is necessary to install the dependencies of a specific…
pythonasked 8 years, 6 months ago Wallace Maxters 102,340 -
8
votes4
answers485
viewsHow to determine the index of items in one list in another
Work with python 2.7. Whereas the following: S_names=["A", "B", "C", "D", "E", "F", "G"] S_values=[1,3,4,2,5,8,10] other=["Z","W","B","S","A","E","X","T","D","G","L","C","F"] I need to find in what…
-
8
votes1
answer4275
viewsLogin to facebook com python
I would like, for educational reason, to login to facebook with a python script. I tried with lib requests import requests s = requests.Session() post_url =…
-
8
votes2
answers1864
viewsSerialize Object to JSON
How do I convert an object to JSON? I even found some codes on the internet that even worked, but my object has some fields that are other objects and so the conversion did not reach the last level.…
-
8
votes4
answers9085
viewsNOT operator in python
In java we have the operator not, we can use it like this: if (!metodo()) { //código } I’m just meeting python now, and I’m having a little trouble: I have a function that adds names to a list: def…
-
8
votes1
answer5375
viewsHow to declare a password (password) input?
I wonder if there is a way to mask the input of characters in the input() python. Ex: Senha = 1234 Entrada = int(input("Digite sua senha: ")) In the entry above I wanted to change the letters…
-
8
votes1
answer478
viewsMatch all coordinates x, y, z from a list of tuples
I have the following list with several points: [(14, 9, 7), (11, 1, 20), (1, 1, 7), (13, 9, 1), (9, 13, 4), (20, 1, 4), (17, 6, 8), (14, 10, 1), (14, 2, 17), (7, 20, 7)] Each element of the list is…
-
8
votes5
answers23915
viewsHow do I know if the variable is an integer in Python?
How can I know if the variable is an integer in Python? I know how to do it in PHP: is_int($variable); // bool(true) But how can I do in Python? Example: numero = 1 #é numero nao_eh_numero = 'texto'…
-
8
votes3
answers646
viewsWhat does it mean to put the 'as' command after the 'import' command in the code below?
'as' is in the send_to_twitter function (msg) import urllib.request import time def send_to_twitter(msg): import twitter as t: CONSUMER_KEY = '1wrnsF5lB8fEWVzRdvlIqdTle' CONSUMER_SECRET =…
-
8
votes9
answers23719
viewsInverting sequence (PYTHON 3)
I have to implement the following: Write a program that takes a sequence of integer numbers ending with 0 and prints all values in reverse order. **Note that 0 (ZERO) should not be part of the…
pythonasked 7 years, 8 months ago Reginaldo Barros da Cunha 137 -
8
votes1
answer12189
viewsHow to create an executable from python
I’m doing a service where I have to do a program that reads and creates files with numerical data. The problem I have is that the computers on which the program will be used are not accessible to…
-
8
votes5
answers10407
viewsIdentify if there is an uppercase letter in the string
I have declared two certain variables, one of which is uppercase and the other only lowercase. See the example below: actor = "Jon Snow" pet = "wolf" How can I identify if it exists at least one…
-
8
votes4
answers392
viewsProgram that returns the unusual numbers of two lists (python)
I’m trying to make a program, in Python, that returns a list with the unusual elements between two other lists. I made the following code: def indice(a,b): ind = [] for i in range (len(a)): for w in…
-
8
votes3
answers429
viewsHow to use Form in Listview Django?
I am trying to create an action for a Listview, the action would be Delete or change a parameter in the table, for example disable user, using checkbox. If I select all and click on this button the…
-
8
votes4
answers5555
viewsDetermine the nth Fibonacci term with recursion
I don’t understand anything about recursive functions, even debugging, is very confusing for me. Someone can explain me in an easy way? I tried to analyze the following code: #!/usr/bin/python def…
-
8
votes1
answer517
viewsParallelize python Odd-Even Sort sorting algorithm
I have developed the following serial code to perform the Odd-Even Sort sorting, which first sorts even/odd and then odd/even. import time def oddevenSort(x): sorted = False while not sorted: sorted…
-
8
votes1
answer2502
viewsWhat are the differences between Flask and Django?
I recently started in the Python language and am currently working on a project using Flask, MariaDB and WebSockets. I see people talk a lot about Django and would like to know the differences…
-
8
votes1
answer1237
viewsDoes the type annotation in a function not guarantee the type in Python 3?
It is known that in Python it is not necessary to define the type when declaring a variable and this is interesting, however, when creating a function, I cannot restrict the types of attributes, so…
-
8
votes2
answers971
viewsAre there static methods in Python?
Are there any static methods in Python? If there are any how do I make a static method?
pythonasked 7 years, 1 month ago Matheus Grossi 321 -
8
votes1
answer424
viewsGraph of Machine Learning
I have a problem to generate a graph using Python - Machine Learning - Naive Bayes model - would plot an F1 (score) for the different values of K, below we have the classifier that gives me the…
-
8
votes2
answers5568
viewsHow to interpolate string in Python?
For example, in PHP, we can do so: $preco = 200; $unidades = 10; $texto_final = "O produto custa {$preco} reais e restam {$unidades} unidades."; You can do something similar in Python or you must…
-
8
votes1
answer702
viewsHow to draw a straight using turtle geometry?
I’m trying to supplement my answer to a question about intersections of circles. In this answer, at a given time, I get an equation of the line in through the coefficients a,b,c: r: a*x + b*y + c =…
-
8
votes0
answers6171
viewsHow to make all possible combinations to arrive at a proposed result?
Well, let’s start at the beginning, at the beginning, at the beginning. I have this program: from itertools import combinations lis = [1,2,3,4,5,6,7,8,9] for i in (3, len(lis)): for comb in…
-
8
votes2
answers160
viewsLittle Python Combat Game
I’m a beginner in programming and I’m trying to make a simple little game to apply my knowledge about conditionals, repetition and the Random module, but I’m having some semantic problems. My goal…
pythonasked 6 years, 9 months ago AmadNicolas 83 -
8
votes2
answers523
viewsEval vs Ast.literal_eval: what are the differences?
In Python it is common to read that ast.literal_eval is an alternative to eval. Are the functions equivalent? Everything one does to another also does? In security matters, there is priority in…
-
8
votes1
answer1603
viewsFormat percentage in python
How should I format the percentage for this example? import pandas as pd flights = pd.read_csv('data/flights_until_june.csv', sep=',') sum_null = flights.isnull().sum()…
-
8
votes1
answer147
viewsWhy do these two ways of initializing the same list in Python generate structures of different sizes?
It is common to need to initialize a list in Python with a defined amount of elements and we can do this in two ways: 1) multiplying the list with an element by the desired amount; or 2) using the…
-
8
votes2
answers1283
viewsHow to access the elements of a set (set)?
I’m studying about ensembles (set) in Python because I’m going to use it in an algorithm to find paths in a graph, it’s for a college discipline that I’m having. I created two set examples using two…
-
8
votes3
answers1885
viewsLongest word in a sentence in the list - Python
The code in Python need to find the largest word in the typed phrase that will be stored in the list, being displayed later. The only thing I know about the resolution of this code is using the…
-
8
votes2
answers214
viewsInverting two variables without using a temporary
How can I reverse the value of a for b and b for a without using another variable? For example, a worthwhile 1 becomes real b worthwhile 3 and b becomes real a that was worth 1. #antes de inverter a…
-
8
votes1
answer4854
viewsConvert a str to datetime in Python
I am creating a task manager that should receive a task with a deadline. This manager will check how many days left to the deadline and let you know when to arrive. However, I am having a problem…
-
8
votes3
answers10568
viewsWhat is the difference between using += and =+ in Python?
I’m having a hard time understanding the difference in logic between: x += n And: x =+ n
-
8
votes2
answers2073
viewsFind the largest and smallest element of a matrix
I have the following code: def processa(matriz): print('----- Matriz Lida -----') for i in range(len(matriz)): for j in range(len(matriz[0])): print(matriz[i][j].center(6), end=' ') print() return…
-
8
votes2
answers196
viewsWhy do I need to use an application server with Django?
Why it is necessary and what is the advantage of using an application server, such as Gunicorn, in a production environment? It would be possible to use only Django talking directly to the server,…
-
8
votes1
answer178
viewsPython 64 bits have advantage?
What is the advantage of using 64-bit Python over 32-bit Python? It would be performance?
-
8
votes2
answers174
viewsFilling a list using its size as a stop criterion
I’m creating a code that defines a function that depends on two variables (Z and N). This program defines the sum of these variables and attaches each possible sum in an empty list. The list must…
-
8
votes2
answers118
viewsWhy does multiple variable assignment create a list when used with the asterisk operator?
Suppose there is a tuple with three values, ('a', 1, 'b'), and you want to assign the first value in one variable and keep the rest in another. For this you can do: a, *b = ('a', 1, 'b') Thus, a…
-
8
votes1
answer304
viewsRecursiveness in Python
Next guys, I have a matrix that is a naval battle board represented by the list: tab = [['.', '.', '#', '#', '#'], ['.', '.', '.', '.', '.'], ['#', '#', '#', '#', '#'], ['.', '.', '.', '.', '.'],…
-
8
votes3
answers190
viewsHow to get the index of the first positive element in a list?
I am looking for a solution to a very simple problem. I need to get the first element of a list greater than or equal to zero. I was able to do this with the following function: def…
-
7
votes2
answers821
viewsIn Python, how to get the default temporary directory?
I am making a program that uses a temporary file to save a serialized object (pickled). At the moment, the program is generating in the /tmp, but this path is specific to Unix/Linux; wanted to take…
-
7
votes2
answers428
viewsHow to open a Unicode file inside a zip?
I tried to with zipfile.ZipFile("5.csv.zip", "r") as zfile: for name in zfile.namelist(): with zfile.open(name, 'rU') as readFile: line = readFile.readline() print(line) split = line.split('\t') but…
-
7
votes1
answer315
viewsDjango 'bool' Object has no attribute '_Committed'
I have a field of sorts FileField and when I try to delete the contents of it, returns me this error message: bool' Object has no attribute '_Committed' To make the upload works normally, the…