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
-
2
votes1
answer45
viewsGet list elements after Insert
I have an empty list that will be fed by inputs. In case, how do I insert the data stored in this list into a database (SQL Server)? I tried this way but it didn’t work. import pyodbc, datetime…
-
2
votes2
answers126
viewsAdding elements to a dictionary only if the key does not exist
I have to create a function that adds the data of a new student to a dictionary. Entree: students: dictionary with the students' data name: student name (key) notes: list of a student’s grades…
-
2
votes2
answers215
viewsHow to access the lines of a file read by readlines()?
I’m trying to use the readlines, but it makes a mistake that I don’t understand the reason, see: arquivo = open("cadastros.txt", "r") loginarquivo = arquivo.readlines()[0] senhaarquivo =…
-
2
votes2
answers118
viewsHow do you make this code more readable for someone who doesn’t know anything about programming?
I will present this code to my math teacher (who knows only algorithms, no Python or any programming language). I’m a beginner in Python, so I know there must be a simpler way to make the code. The…
pythonasked 4 years, 8 months ago Paulo Andrade 43 -
2
votes1
answer76
viewsCorrect use of lambda with filter()
Here is a practical example of a script that simulates a seller’s sales days and extracts only the days when the seller hit the day’s quota. The list represents the month (I entered only 3 days for…
-
2
votes3
answers516
viewsHow to compare two JSON objects with the same elements in Python
I have two Apis that bring me the data in JSON. I’m just not able to make the logic to compare the two. API 1: API 2: My logic is to compare the two on the die FlightID and if it’s the same, give me…
-
2
votes2
answers181
viewsReading and processing XML file from a CVE (Common Vulnerabilities and Exposures) database with Python
By using the Annexes lista.txt and cve.xml develop a Python script that: open and read the ". xml" extension file made available at the end; search the file for all occurrences of CVE ID in the…
-
2
votes3
answers307
viewsHow to use if, Elif and Else
GOTHAM CITY Challenge (level 1) You are a police officer and need to report a criminal activity and on report you will give a number from 0 to 10 regarding the level of the crime. Make a code that…
-
2
votes1
answer540
viewsWhy does Python consider an empty string ('or "") to be present in a simple variable with characters, but not in a composite one?
When doing basic programs asking for user input, and testing if it is empty with in because of another variable that defines possible inputs, I come across the following: if '' in 'abc': print('not…
-
2
votes1
answer27
viewsRecord an index-specific value and treat the values
The number of Likes is cumulative, that is, if the post has 0 Likes and receives 5 Likes, it will have 0 + 5 =5 Likes. If soon, this same post receives 7 Likes, will have 5 + 7 = 12 Likes. If the…
-
2
votes2
answers98
viewsHow to create a program that checks the entry of a variable and only proceeds until it is valid (Type - Value)? Python
How to create a program that checks the entry of a variable and only proceeds until it is valid (Type - Value)? Python In this case I created a function to check if a value and number and returns…
-
2
votes1
answer1301
views'Model' Object is not iterable
As soon as I click on a button that calls my view to edit the Row of the table in question shows me the error: 'Meumodel' Object is not iterable. I’m using Django 2.1.15 Python 3.8.1 SQL server…
-
2
votes1
answer423
viewsError: not all Arguments converted During string formatting
I’m taking the Python 3 course on video and I’m in exercise n° 82. Even though my code and the teacher’s code are almost identical, mine is making the mistake not all Arguments converted During…
-
2
votes1
answer141
viewsPerform data counting based on grouping 2 or more columns in a Pandas.Dataframe
I want to find in this Dataframe, the 3 best user_id for Nome prova. That is, those who have the highest number of values 1 in the correct column ( such column is composed of values 0 and 1 ): Nome…
-
2
votes1
answer69
viewsimage processing (KNN classifier) - python
When using Kneighborsclassifier, I am getting the following error: /Feature Extraction (Python)/KNNpy:58: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please…
-
2
votes1
answer912
viewsSet bar space using matplotlib
Good afternoon. I’m filling a bar chart but I can’t adjust the spacing between the 3 different bars of the same. # plota os resultados diameters = ['<=102', '103-152', '153-203', '203-254',…
-
2
votes1
answer6781
viewsCenter text in python
Good afternoon, I’m creating a program to generate certificates, but I’m having trouble centralizing the names, how could I do that? For every name is of a size. I tried the center(), but it didn’t…
-
2
votes1
answer71
views"Elif" does not allow to execute what is expected
If you do if each one alone and run with else, the calculation is correct. But using both (if and elif) does not recognize the differences and does not display the expected results. There will only…
-
2
votes3
answers745
viewsReturn the positions of the largest number in a matrix
I need a code that returns the position of the largest element of the matrix, and if this element repeats, the code returns all positions that this largest element appears. Below, in my code, I can…
-
2
votes2
answers46
viewsPrint an attribute of several classes
I am creating a program that will launch the establishment products and creating each product being an object already that they have type, name and price. I want to print a specific attribute of…
-
2
votes1
answer69
viewsObjective of str()
I’d like to know what role the function plays str() on line 33(code does not work without this function, gives this error: Typeerror: Unsupported format string passed to list.format) jogadores =…
-
2
votes1
answer883
viewsI wonder how I get the result of a command in python that runs in CMD and save in a variable,
That program drips a IP, would like to pick up the result of that ping that is done on this line os.system ('ping -n 4 {} '.format(ip)) that opens the CMD and drips the IP, and save to any variable,…
-
2
votes1
answer167
viewsLoop the loop after performing functions
I’m having difficulty in this code, I adapted in two functions as guided by prof. but I’m having difficulty in the final phase, which asks: use for or while n times (n is equivalent to the quantity…
-
2
votes2
answers46
viewsInserting error message to user
Make a program that receives two numbers. Calculate and show: The sum of the even numbers of that range, including the numbers typed. The multiplication of odd numbers in this range, including those…
pythonasked 4 years, 7 months ago Vini Rocha 21 -
2
votes1
answer96
viewsCalculate k-Mers of DNA sequences in a fasta file- In python
I want to calculate the amount of k-Mers in a DNA sequence. However, the file I have has several sequences and also identifiers . Note: k-Mers are the lengths of a sequence for example a sequence…
-
2
votes1
answer629
viewsProgram in python regarding the factor of odd numbers up to the one typed by the user
I must ask the user to enter an odd number and return on the screen the sum of the factorial of all the odd numbers until the one typed by the user. I did the part that validates if the number typed…
-
2
votes1
answer67
viewsTensorflow Convolucional Neural Networks
Hey, you guys, hey! I have a problem, I believe, in my training set. I have a numpy array with 649 images for training my network however when starting the training(model.fit) I see that only 21…
-
2
votes1
answer46
viewsSend all returned data in the same email
I have the following query: cursor.execute("SELECT raddb.StockMinimo.Id, raddb.StockMinimo.Produto, Minimo, Quantidade FROM raddb.StockMinimo LEFT OUTER JOIN raddb.StockProdutos ON…
-
2
votes1
answer102
viewsShould I specify the type of return of a procedure in Python?
For some time I have studied and learned a little more about Python. I recently read an article about the description of python typing using the module typying. Since I learned about this feature I…
-
2
votes1
answer303
viewsHow to open a txt file that has a space in its python name?
I’m learning to code in python and I’m having trouble opening a specific file. In case I can open text documents normally, but when there is space in the file name it does not locate the file.…
-
2
votes1
answer130
viewsList containing only the last element in Python
I’m going through a text file and putting its contents in a list of objects, in which each object contains two "string-like" attributes: word and meaning... The problem is that after I go through…
-
2
votes1
answer44
viewsModifying privileges with python
I am facing the following problem, I am increasing the privileges with "Elevated", but after running the.mkdir (), I would like him to lose his privileges and return to being an ordinary user.…
-
2
votes4
answers669
viewsHow to access indexes backwards within a list?
I’m taking the notes that make up the triads of the major chords. For this, I created a list of all possible notes, and according to the chord typed I see the list looking for the first largest,…
-
2
votes2
answers2053
viewsEoferror: EOF when Ading a line
I’m doing a program that’s a resolution of this issue of the Computer Olympiad. A, B, C = input("A").split(), input("B").split(), input("C").split() A, B, C = int(A[0]), int(B[0]), int(C[0]) if A…
-
2
votes3
answers723
viewsPython: conditional sum with variable condition
good morning. The task is as follows, I am trying to make a 'a,b,c' curve of products per company. I have the following df as an example: df = pd.DataFrame({"empresa":["HST", "HST", "HST", "HSC",…
-
2
votes1
answer2915
views'Nonetype' Object is not subscripteble in Python
I have an exercise in defining a class Triangulo and a method retangulo(), who will return True if the object is a rectangular triangle. I always liked to use lists to solve my problems, so I wrote…
pythonasked 4 years, 5 months ago Bernardo Lansing 121 -
2
votes0
answers47
views"Attributeerror: classifierFinal' Object has no attribute 'log_softmax" when trying to train a neural network using pytorch
I’m learning to use the pytorch and I’ve stumbled upon the mistake that won’t let me continue. My code: import pandas as pd import numpy as np import torch.nn as nn from skorch import…
-
2
votes2
answers378
viewsPrime Numbers with While and For
I don’t understand how a command finds prime values: for i in range(2,30): j = 2 counter = 0 while j < i: if i % j == 0: counter = 1 j = j + 1 else: j = j + 1 if counter == 0: print(str(i) + " é…
-
2
votes1
answer76
viewsSum of Values within Compound Lists
I have a question about how to add certain values in Composite Lists. And I wanted to know that there is a quick method for this very. lista_total = [] d = 0 while True: nome = str(input('Nome: '))…
-
2
votes2
answers283
viewsjwt.Decode - what is the need for a list of algorithms?
I am studying Python and needed to solve an exercise using JWT (JSON Web Tokens). It was necessary to create a token and verify the validity, searching for example codes, found in the documentation…
-
2
votes1
answer41
viewsKivy - Change keyboard cursor position (Caret) after formatting textinput with mask
In a Textinput where the user type the CPF, control the validation and formatting in an on_Text event. After typing the 11 digits and validating the CPF, I format with the mask, however, after…
-
2
votes1
answer2901
viewsValueerror: could not Convert string to float: 'red'
Hello, I’m trying to make a model for deciding white and red wines, this is my code: from sklearn.model_selection import train_test_split import keras from keras.models import Sequential from…
-
2
votes2
answers397
viewsLONG delay in requests.get Python
I’m having a problem that when I perform requests.get diverse sometimes python starts to take A LONG time to get the request. I already thought it may be the API itself refusing my access, because…
-
2
votes2
answers128
viewsHow to display a list always sorted as new items are inserted
I am trying to implement a list, in which, each number typed is inserted and counted in sequence, as in the example below: lista = ['0'] while True: ean = input('digite aqui: ' ) lista.append(ean)…
-
2
votes1
answer132
viewsList modification problem within a function (python)
def f(i): return i + 2 def g(i): return i > 5 def aplicacao(L, f, g): lista_f = [f(i) for i in L] lista_g = [g(i) for i in lista_f] L = [L[k] for k in range(len(L)) if lista_g[k] == True] if…
pythonasked 4 years, 4 months ago user158657 105 -
2
votes1
answer95
viewsConsulting previous index in Python
That question is a continuation of this here As previously reported, I have a script that does a txt search for a keyword (APPLE) and if it is true, it alters another part ("00" or "01" or "02") of…
-
2
votes2
answers115
viewsRegression Graph in R or Python
It is possible to play this Regression graph in R or Python? Obs. This graph was produced using the Acquire 4 QAQC object. Link And this is the model I’ve created so far. dados =…
-
2
votes2
answers328
viewsSelect column numpy no for
I’ll be very brief. I’m just wondering how to put in for when the values of the first column of the matrix is less than zero, the values of the second column will be a. from scipy import stats from…
-
2
votes1
answer613
viewsCount how many occurrences of one number there are in another, recursively
Using Python, write a recursive function that determines how many times a number k 2-digit occurs in a natural number n. For example, the number 21 occurs twice in 2135219877. The problem with my…
-
2
votes1
answer373
viewsConnect to a host via SSH and go to another with ssh - Python tunnel
The code below (main.py) provides access to a host through SSH and creates a tunnel for the IP to be accessed by 127.0.0.1: import paramiko from sshtunnel import SSHTunnelForwarder from paramiko…