Posts by Onilol • 331 points
16 posts
-
0
votes1
answer58
viewsA: What should I put into parenthesis?
You are trying to initialize the bank asynchronously, so the promise. As promises need to be resolved for you to see some result, so you have two options: async function conectaNoBanco(){ const…
-
0
votes2
answers104
views -
2
votes3
answers85
viewsA: Error searching string inside another python string
I gave a little refactoring in your code: def about_time(self): temp_atual = datetime.datetime.now() if any(_ in self.frase for _ in ('sao', 'são')): print(temp_atual.strftime("Agora são %H horas,…
-
1
votes1
answer492
viewsA: Script that takes a list of integer numbers, sorts and removes duplicates
I believe it’s self-explanatory, the function set() removes duplicates and function sorted() ordains lexicographically an eternal: def remove_repetidos(lista): return sorted(set(lista))…
-
0
votes5
answers7817
viewsA: Sum of each element of two lists
Another option would be this: D = map(sum, zip(A, B)) basically a reduced form of the other answers.
-
1
votes3
answers559
viewsA: Python - Find numbers larger than average
This should help you: def somar_elementos(lista): media = sum(lista) / len(lista) return media, len([n for n in lista if n > media])
-
3
votes3
answers502
viewsA: Python - Cycle for as an alternative to the while cycle
If you just want the end result: print('soma = ', sum(range(-20,0,2)))
-
1
votes1
answer45
viewsA: Problems configuring views using Jango
Trivial error: def post_list(request): posts = Post.objects.filter(published_date__lte=timezone.now()).order_by('published_date') return render(request, 'blog/post_list.html', {'posts' : posts})…
-
1
votes1
answer839
viewsA: How to perform operations between arrays in python
Let’s go in pieces: As I understand it, you have two lists (in Python, an array is called a list): x = [1, 5, 7] y = [3, 6, 2] The first part of your problem can be solved as follows: z = [(v[0] -…
-
0
votes1
answer61
viewsA: How to reuse class values?
As commented by Anderson Carlos Woss, you need to be careful with multiple inheritance, in your case, I see it as follows: A cross section has one Material and a Geometria, but it is not by itself a…
-
2
votes2
answers106
viewsA: Function that determines whether all letters contained in one string are in the other
Another way of doing: def isWordGuessed(secretWord, lettersGuessed): return set(secretWord).issubset(set(lettersGuessed)) The advantage I see in this case is to save the verification of repeated…
-
1
votes1
answer517
viewsA: Python import file from variable
Try it here: import sys sys.path.append(a) The modules are searched in this order: Current directory Environment variable PYTHONPATH Default installation address Use this link as a reference (in…
-
0
votes2
answers997
viewsA: How to open a screen with a pre-filled HTML form?
In your view, when instantiating the form, add the instance of the desired object. meu_objeto = MyObject.objects.get(pk=meu_id) form = MyForm(instance=meu_objeto) That should solve your problem.…
-
1
votes3
answers858
viewsA: How to make a Union of two queries using Django Filter
Depending on the type of relationship you are looking for, this can help you: Table1.objects.filter(user_id__in=[x.user_id for x in Table2.objects.all()]).order_by('created_at') Anyway, you can test…
-
1
votes1
answer66
viewsA: Python: Serialization of json namedtuple classes
Although you advise against this practice, what you want to do can be done as follows: Emp.tojson = lambda self: json.dumps(self._asdict())
-
2
votes1
answer174
viewsA: Generating functions: What are the advantages of using them?
In a very basic way, generators are lazy, that is, the next element to be "spit out" will be processed upon request, unlike a list where all elements are processed and are in memory. Another…