Questions tagged as 'python-3.x'

2
answers

How do I delete empty lists in my list of lists?

I have the following txt file: 1 2 3 4 5 6 7 8 9 2 3 4 5 6 7 6 8 9 3 4 5 6 7 7 8 8 9 1 2 3 4 5 6 7 8 9 4 5 6 7 8 9 10 11 5 6 7 6 7 8 8 9 15 When I open it and generate a list of lists many positions are empty, to try to solve this prob...
asked by 25.08.2018 / 05:31
1
answer

Why does the '-1' have to be placed right after a variable?

Note: the code is from a book that teaches programming Code: def transação_salva(preço, cartão_de_crédito, descrição): arquivo = open("transactions.txt", "a") arquivo.write(" %s %16.2f \n %s %16s \n %s %17s \n ------ \n" % ("Preço:"...
asked by 17.02.2017 / 01:10
3
answers

Reverse method returns None

I'm applying the reverse method to a list and it returns None . Ex. teste = ['audi', 'subaru', 'fiat', 'ford'] print(teste.reverse())    None     
asked by 12.09.2018 / 03:10
1
answer

How to sum values from a csv using Python?

I have a csv file similar to this one, with all the information of all municipalities in Brazil (I shortened the csv to not be too long): ESTADO,MUNICIPIO,HABITANTES,AREA AC,ACRELÂNDIA,12538,1807.92 AC,ASSIS BRASIL,6072,4974.18 AC,BRASILÉIA,21...
asked by 03.10.2018 / 23:43
2
answers

Count certain characters in a word in python

I'm making a command to help you read a globe. entrada = int(input("Quantos centimetros no globo: ")) km = entrada * 425 m = km * 1000 cm = m * 100 print(entrada, "centimetros no globo equivalem a:", km, "quilometros", m, "metros e", cm, "cen...
asked by 15.12.2017 / 19:37
2
answers

List of objects in Python

I'm doing a function that returns an object list. Code snippet: def guarda_word(lista_palavras,lista_objeto,indice): for i in lista_palavras: if bool(lista_objeto) == True: # a list de objeto esta vazia i = PalavraIndi...
asked by 07.10.2017 / 20:34
2
answers

How to do string interpolation in Python?

For example, in PHP we can do this: $preco = 200; $unidades = 10; $texto_final = "O produto custa {$preco} reais e restam {$unidades} unidades."; Is it possible to do something similar in Python or do I need to concatenate always?     
asked by 22.12.2017 / 07:10
3
answers

Test sum function

Hello everyone, how are you? First of all I want to say that it is a pleasure to be part of this community. I'm studying python on my own, I found a course per application, I'm already in the functions part but I did not understand correctly the...
asked by 13.06.2018 / 14:20
3
answers

Compare dates in Python

Good afternoon!     I need to solve the following scenario in python: I have one or more .txt files in a folder, but I want to return only the files that have the modification date according to the date I want (initial and final), but I'm not ab...
asked by 05.09.2018 / 15:18
2
answers

Django + Python, modal display using {% if%} in the template

I'm doing a check if there are active classes, if there is not a modal and not the registration form, but it is not working: views.py: from django.shortcuts import render, redirect from django.core.mail import send_mail from django.temp...
asked by 17.09.2018 / 15:03