Posts by Murilo Sitonio • 630 points
26 posts
-
0
votes4
answers350
viewsA: How to add values from a dictionary with arrays by the Python key?
>>> d = { ... 'tvmv': [121, 250, 48, 45, 54, 120, 115, 138, 60, 30, 274], ... 'avic': [358, 60, 40], ... 'hotels_resorts': [60, 31, 45, 50, 300, 165, 40, 46], ... 'avani': [70, 40], ...…
-
0
votes1
answer43
viewsA: How to call a function by loading a string in Django?
The Django templates support all the operations you’re doing inside the view. Do something like: return render(request "posts.html", {"posts": Album.objects.all()} Within the template you can…
-
0
votes1
answer249
viewsA: Django - Filter queryset into a form using a value present in the view
You don’t need to pass this on to RegistrarionForm. As the CNPJ is unique you can get the object that represents the company in your view and associate it with the employee you created with the…
-
1
votes2
answers38
viewsA: Secret Word Preview Does Not Update - Hangman Game
Make the following changes: senha_list = ["_ " for l in palavra_secreta] ... print("A palavra:", " ".join(senha_list)) ... elif an not in palavra_secreta: ... print("Você acertou uma letra!") for i,…
pythonanswered Murilo Sitonio 630 -
5
votes1
answer104
viewsQ: Is it recommended to explain all variables?
This is a question as to the readability of the code or if there is any style pattern as to this. Well, the Zen of Python tells us that Explicit is Better than implicit. but how to interpret this?…
-
0
votes1
answer45
viewsA: Update on Mongodb
With the information you provided it is practically impossible to answer you. I explain: 1) You have not given any background information (you will include a document in the collection and want to…
-
0
votes1
answer229
viewsA: How is the pymongo connection established?
To documentation sets a cursor as: A Pointer to the result set of a query. Clients can iterate through a cursor to Retrieve Results. That is, the cursor only points to the result, rather than…
-
1
votes1
answer229
viewsQ: How is the pymongo connection established?
I’m building a program that scans a database every minute, and if some conditions are met, the program makes several requests via Apis and talks to Mongodb to process and save the data. It is very…
-
2
votes1
answer123
viewsA: how to remove None from the list
Consider checking what Anderson said in the comment, but answering your question directly: [x for x in lista if x is not None] >>> lista = [5, None, 3] >>> lista = [x for x in…
pythonanswered Murilo Sitonio 630 -
1
votes2
answers562
viewsA: How to go through two lists of different sizes [PYTHON]?
for t in team: for m in mapList: TesteTime = Time(team[t], m, 0,0,0,0,0,0) TesteTime.leitura(team[t], m) TesteTime.handicapMedio() TesteTime.HandicapVitoria() …
-
0
votes2
answers360
viewsA: Extract information from a tuple and place in different variables
I think first of all, you should take a step back and study about how manipulate lists (you are always assigning the same list to all fields in somedict) and as a JSON is structured (First you store…
-
3
votes2
answers2471
viewsA: How to select JSON elements with Python?
If you want all the titles: for artigos in noticias.get('articles'): print(artigos['title']) If you only want the first 10: for artigos in noticias.get('articles')[:10]: print(artigos['title'])…
-
0
votes1
answer89
viewsA: Adding a number to an array gives an index problem
inputs and one are arrays of different structures (inputs can be viewed as a list of lists and one just like a list), so your loop won’t work. By the way, you don’t even need the loop since you…
-
1
votes1
answer74
viewsA: How to save peak detection outputs (Z-score algorithm) to a single file?
Using Numpy: datafile_path = "seu_diretorio/datafile.txt" data = (np.array([tracos, picks])).T with open(datafile_path, 'w+') as d: np.savetxt(d, data) Or a more direct solution: datafile_path =…
-
1
votes3
answers243
viewsA: How to save file without overwriting the previous python?
As @Anderson Carlos Woss commented above you just need to change nome1 and nome2, but if you don’t always want to open the code and change it every time you run or if you want to let the user…
-
1
votes1
answer194
viewsA: How to fix a wrong JSON?
It’s really hard to answer since you didn’t say anything about as want to rewrite the JSON (you just want to rewrite it to become a valid JSON, you want to insert some data that may be missing or…
-
1
votes0
answers185
viewsQ: How to position an image in reportlab using pdfrw as flowable?
I’m using the reportlab to generate reports. I can define the creation process in four steps: 1) take the data via API, 2) filter the data, 3) generate the graphics with the matplotlib and 4) insert…
-
0
votes1
answer174
viewsA: My Python code works, but I don’t understand why an int()
Your problem is in the last condition, more precisely in dias = dias - (meses * 30) (which you can simplify to dias -= (meses * 30)). If you don’t force months to be a whole (using int()), dias -=…
-
3
votes2
answers98
viewsA: How to pass a Dict within a function, to be used in any case if necessary?
The @Breno response was very good, I will only complement if you want to change more than one key in the same function call ChangeDictKey: def ChangeDictKey(dictionary, oldKeys, newKeys): for…
-
3
votes1
answer197
viewsA: Death Note in Python: Problems with two Elif’s in the code
Create a list to store the entered names and check if there is any repetition. nomes = [''] You will need to change the following conditions: if morte == "" and nome != usuario and nome not in…
pythonanswered Murilo Sitonio 630 -
2
votes2
answers39
viewsA: Dictionaries dependent on other dictionaries
for x in dependencias_complicado.values(): for y in x: print(y) análise_complexa topologia análise_real cálculo1
pythonanswered Murilo Sitonio 630 -
7
votes3
answers6345
viewsA: How to turn upper-case and lower-case letters into upper-case letters in Python?
texto.swapcase() #'aQUi tEm UMa sTRINg'
-
0
votes2
answers100
viewsA: Problem inserting data into CSV file
You need to set the delimiter to semicolon: writer = csv.writer(dados, delimiter=';') A tip: if you want to open the file in excel, why not generate a direct . xlsx file? Take a look at the…
-
-1
votes3
answers92
viewsA: Argument error in python 3.7
preco = float(input("Valor da Mercadoria : ")) parcelas = int(input("Em quantos parcelas você quer dividir ? ")) valor_desconto = preco*0.9 print("O valor a vista com desconto é de R${}…
pythonanswered Murilo Sitonio 630 -
2
votes1
answer401
viewsA: While Python repetition structure
You’re not incrementing any variable, just endlessly assigning data_futura with data_min + timedelta(dias_por_mes*meses). Do so: data_min = data_min + timedelta(dias_por_mes*meses) It is worth…
-
0
votes1
answer1245
viewsQ: How to create a CSV file via Python by keeping the decimal separator in the same place?
I have a Python script that makes a request via API and saves the data in a CSV file. The data is stored in different lists in Python and should be saved in different columns in the CSV file. The…