Questions tagged as 'python'

2
answers

Multiple of 10 closest to one sum

def multiplo(x): somamulti= somaImpares(x) + somaPares(x) if somamulti/10==0: return somamulti/10 else: return In this function I did what happens is as follows: somamulti adds 2 values, in this case it can...
asked by 17.03.2015 / 22:52
1
answer

How to add elements in the tuple using a function?

def funcao(): int(input('insira um número:')) tupla = (funcao(), funcao(), funcao(), funcao()) print(tupla.count(9)) print(tupla) insira um número:9 insira um número:9 insira um número:9 insira um número:9 0 (None, None, None, None) P...
asked by 28.10.2018 / 05:15
3
answers

How to validate if a value is a tuple having a string and an integer? [closed]

I want to write a function that takes an argument (any type) and returns true if the argument is a tuple (double, double elements of 2), where 1 is a name ( str ) and 2 is an age (% with%). Otherwise it returns int . My fir...
asked by 05.11.2018 / 11:32
1
answer

Filter elements of a tuple based on a value in a certain index

I want to write a function in Python, call separates, which receives a tuple tup whose elements are pairs (double of 2 elements), where the 1st element is a name (a string) and the 2nd element is an age (an integer), as described in the previous...
asked by 07.11.2018 / 03:06
2
answers

What is the difference between string.split (',') and string.rsplit (',') in python?

When using these lines in the python terminal, I could not find a difference between any of them. I researched but I did not find anything about it, at least in Portuguese. What would be the difference between them? x = 'apple, banana, cherry'...
asked by 01.12.2018 / 14:43
1
answer

How to assign the elements of a list to different variables in Python?

I have a list, like the following: lista = [1, 2, 3, 4, 5] Even though I do not know how many elements are in the list, how do I assign each element of the list to a different variable? (as in the example below) elemen1 = '1' elemen2 = '2...
asked by 28.11.2018 / 14:30
1
answer

Create a program that receives a line of text and counts the vowels with their respective histogram

exercise: Create a program that receives a line of text and counts the vowels with the respective histogram as follows:    Example: Last line of text: "Next Wednesday is   holiday. " a : ****** (6) e : *** (3) i : *** (3) o : **...
asked by 07.10.2018 / 20:18
1
answer

Show list items by filtering by date.today ()

I have a list that I sort by position in my models.py , however I have the start_date field that I want to use as a validator for the item to be visible or not. But it is not working: views.py : from django.shortcuts...
asked by 27.09.2018 / 20:32
1
answer

Get Documents directory with python automatically

I need to automatically get the document folder address of any Windows with Python. Currently in my script I determined it as shown in the variable main_folder , however whenever I change from PC I have to change that address. Below i...
asked by 09.10.2018 / 23:23
2
answers

Get specific column csv with python

I have a method that opens a CSV file but I would like to go directly to a specific column, I tried to do list2 = [row.split()[3] for row in f] , but it returns a piece of the file, not the column. Is it possible to do this without using P...
asked by 08.10.2018 / 23:02