Questions tagged as 'python-3.x'

1
answer

Know the smallest number with the function min ()

I want to know the least number of this list, which I present below. I do not know where I'm fooling myself, I think I need to convert the list. Example: lista=[1, 3, 5] def min(values): smallest = None for value in values:...
asked by 25.06.2018 / 18:05
2
answers

How to find out if a number is a sub-number

I would like a code, with explanation (if possible of course), to know if one number is sub number of another. Example:    P = 101   Q = 100001010057 So P is sub number of Q . Thank you in advance.     
asked by 27.02.2016 / 02:46
2
answers

Remove specific characters in Python

My question is the following, in this code snippet I'm removing a character that I specify with replace() : lista = [["de carlos,"],["des.dd carlossd,"],["Peixe, texto!"]] lista_separados = ['.',',',':','"','?','!',';'] for i, j in en...
asked by 07.10.2017 / 05:20
3
answers

get the 3 largest numbers from a list in python

Can someone help me find the error?    "" "" # TODO: implement this function def top_three(input_list): list1 = [2,3,5,6,8,4,2,1] input_list = sorted(list1, reverse=True) return input_list[:3] print (t...
asked by 23.07.2017 / 02:15
2
answers

Find the largest palindrome made from the product of two 3-digit numbers - Python

I have a problem. I'm creating an algorithm in Python to find the largest palindrome made from the product of two 3-digit numbers. Code: i = 0 while i <= 999: temp = str(i * 999) tempInverso = temp[::-1] if temp == tempInvers...
asked by 02.08.2017 / 22:19
1
answer

Limit Input of Python 3 numbers

Using the following code I want to limit from 0 to 2000 the number that can be reported by num import collections num = int(input('Digite um número inteiro: ')) #Inputar número inteiro binario = bin(num)[2:] #Cortar o 0b sequence = bi...
asked by 13.12.2018 / 15:23
1
answer

Encode problem in Python

At some point in my code I get a% var of% of type str containing% with of%. while doing var2 = var.encode() print(var2) is printed var The original word would be 'SENTENCE' When doing SENTEN\u00c7A returns me b'SEN...
asked by 18.12.2018 / 19:04
2
answers

Print the minimum number of the list?

I have this code and I can not get the number -1 shown. Give an error:    Not supported between instances of 'str' and 'int'. From what I've seen from other forums there is a comparison of strings with integers. How can I overcome this?...
asked by 10.04.2017 / 17:29
2
answers

Imports in file __init__.py

I am studying the documentation of Django and I noticed that in some __init__.py files there are imports, I know that the __init__.py file defines a module but I do not understand why it imports.     
asked by 09.08.2018 / 20:26
2
answers

How to make a class inside another inherit a variable instantiated from the latter in python?

See the following python script: class a: def __init__(self,n): self.n=n class b: def __init__(self): ## o que botar aqui para receber a variável self.n ##...
asked by 24.01.2017 / 20:37