Questions tagged as 'python'

2
answers

Sort dictionaries and submit 20 first

I have a dictionary with words and their frequency. Genre: dic = {walt: 2, disney: 1, ola: 5, ...} To order the dictionary, I did this: aux = sorted(dicionario, key=dicionario.get, reverse=True) And to present the top 20 wanted to do s...
asked by 17.12.2018 / 01:58
1
answer

What is the difference between Python versions 3.4, 3.5, 3.6, 3.7? [closed]

I thought Python only upgraded versions 2.7 to maintain compatibility but did not abandon previous versions of 3.x. But he insists on updating versions 3.4, 3.5, 3.6, 3.7 constantly. What do these different 3.x.x versions have to do differently?...
asked by 03.08.2018 / 21:35
2
answers

How to implement this while not from Python in C?

I am studying a code in Python that I need to transform to C, but the part that is confusing me is this: while not(f1 == 0 and fn == 1): ... How would this same C code be?     
asked by 04.09.2018 / 22:34
3
answers

Count the most popular words

I'm trying to find the number of occurrences of a list of words in a text: from collections import Counter def popularidade (texto, palavras): texto = texto.lower().split() palavras = palavras.lower().split() lista = [] for...
asked by 10.04.2018 / 11:34
2
answers

Primitive type int () in Python

I'm a beginner (1 semester of TADS), the maximum programming I saw was programming logic and now I started studying > Python . In the Python course of Video Course he taught that the primitive type int () should be written as: n1 =...
asked by 27.03.2018 / 02:41
2
answers

How to replace typed letter in python?

Hello everyone, I want to develop a script that will replace a letter typed by another one, so it would look like a = e, b = f. I spent some time trying to create an algorithm for this function but the interpreter only replaced one letter at...
asked by 03.05.2017 / 03:26
2
answers

Program that warns a secret number using bisection search

Create a program that guesses a secret number using bisection search! The user thinks of an integer between 0 (inclusive) and 100 (not inclusive). The computer, using bisection search, gives a hint and the user responds with h (high), l (low)...
asked by 17.04.2018 / 17:19
2
answers

Recursive function to return string in reverse

I need a recursive function that returns the string that it receives as a parameter inverted , I got this function: def stringinvert(palavra): if palavra < 10: print(palavra) return stringinvert(palavra[::-1]) print(st...
asked by 23.04.2018 / 17:21
2
answers

Vector names and ages - Python

I want to create two vectors, one for names and one for ages, which can store 10 people. I think it would be: pessoas = [] idades = [] for c in range(10): pessoas.append(input('Digite o nome da pessoa: ')) idades.append(int(input('D...
asked by 15.05.2018 / 15:21
2
answers

How to implement Fibonacci more efficiently using dictionaries?

A recursive Fibonacci implementation is: def F(n): if n == 0: return 0 elif n == 1: return 1 else: return F(n-1)+F(n-2) The problem is that it is a little inefficient, since, for example, to calculate F (5), we calculate F (3) m...
asked by 22.04.2018 / 13:40