Questions tagged as 'python'

1
answer

Discover common elements in various lists

I have the following code: list1 = ['a', 'x', 'c', 'b', 'm'] list2 = ['f', 'x', 'a', 'c'] list3 = ['c', 'e', 'x', 'b', 'p', 'k', 'l'] How do I find the common elements, so that I get a list like this: comuns = ['x', 'c']     
asked by 04.06.2016 / 11:50
3
answers

NameError: name 'ana' is not defined

I'm a beginner in python and needed to do a program that checks if a given word is palindromous. The program would then be: #encoding: utf-8 palavra = input ('Palavra: ') if palavra == palavra[::-1]: print ("%s é palindrome" %palavra) else...
asked by 13.07.2016 / 04:15
3
answers

Remove element from a list by key and by value

I have the following list my_list = [1,2,3,4,5,6,7,8,9] Let's say I want to remove num 7, by value and / or key, and stick with: my_list = [1,2,3,4,5,6,8,9] How do I do it?     
asked by 21.06.2016 / 12:01
2
answers

Instance in Django model with problem

I'm working on a project with multiple apps. The department app model is as follows: from emails.models import GerenciarEmails class Departamento(models.Model): #modelo de grupos de disciplinas class Meta: verbose_name = 'Departamento'...
asked by 12.11.2015 / 19:42
1
answer

How to repeat a call of a function of every X seconds in PyQt?

I'm developing a small application in Pyqt4 where I need to load the data into a table coming from a Webservice. This I was able to do quietly. But now, I need to update this every 1 minute. How can I do a repetition of a call to a function e...
asked by 11.11.2016 / 12:14
1
answer

How to read Yaml with Python?

How do I read a file or Yaml code with Python? Is it necessary to install anything, or can you do it natively? Example: fruits: - Apple - Orange - Strawberry - Mango     
asked by 16.11.2016 / 11:50
2
answers

Sort dictionary by Python value

I have a dictionary with the following format dic={759147': 54, '186398060': 8, '199846203': 42, '191725321': 10, '158947719': 4} I'd like to know if there's any way to sort it by value and print it on the screen. So the output is. '15894...
asked by 18.12.2016 / 05:18
3
answers

How to make an error message for this situation?

arq=open('filmes.txt','r') filmes = arq.readlines() def buscaPorGenero(): genero=str(input("Digite o gênero do filme: ")) while(True): for linha in filmes: linha = linha.split(";") if genero in str(linha[1]): prin...
asked by 12.12.2017 / 03:06
3
answers

How to open remote content with python?

In PHP, when I want to get a remote content (some url, for example), I use the proper functions to open files and this works perfectly. Example: file_get_contents('http://pt.stackoverflow.com/') And in Python, what is the correct way to...
asked by 13.08.2015 / 17:26
1
answer

What is the best way to do Python expositoning? Double asterisk or math.pow?

What is the best way to do Python expositoning? Should I use the ** or math.pow ? Example math.pow : > math.pow(3, 4); #Imprime: 81.0 Example with double asterisks ? > 3 ** 4 #Imprime : 81 What should I...
asked by 18.08.2015 / 17:30