Posts by Woss • 73,416 points
1,476 posts
-
15
votes1
answer137
viewsQ: How can the search for an element in a set be O(1)?
In accordance with the official Python page as to the complexity of time algorithms, sequences list and set have the following characteristics:: List Set Highlight for the operator in, which…
-
2
votes1
answer16
viewsA: How to Check numbers contained in a query in a field
Just use the function explode to generate a array from their string and check with in_array: if (in_array($numero, explode(',', $row['id_rota']))) { // Número está na sequência de ids }…
-
7
votes2
answers770
viewsQ: What is the difference between namedtuple and Namedtuple?
To module documentation typing states that the two code snippets below are equivalent. Using typing.NamedTuple: from typing import NamedTuple class Employee(NamedTuple): name: str id: int Using…
-
6
votes1
answer353
viewsA: What is the function of Python descriptors?
The following response was based on the article Descriptor Howto Guide, written by Raymond Hettinger¹, in the official Python documentation. Definition and introduction In general, a descriptor is…
-
0
votes1
answer1008
viewsA: Write a function: int Solution(int A[], int N);
To do this, you just start a variable, i, in 1, check that she is not in A; if you are, return i, otherwise increase i and continue until the condition is true: def solution(A, N) -> int: i = 1…
-
1
votes2
answers139
viewsA: Set functions for equal values and values in ascending order - Python
To count how many are of a given sex, the logic is quite simple: go through the list and when you find a record with the desired sex, add a counter. Basically, it would look like this: def…
-
57
votes2
answers897
viewsA: <br> is obsolete?
No, it’s not obsolete. The element <br> defines a new line break in text, not in layouts. Semantically speaking, such an element should never be used as the layout. Just see what the W3C /…
-
2
votes1
answer38
viewsA: Run event only if another event has already been run
What you can do is assign the listener of the second event only when the first event occurs; and, when executed, remove the listener, so that it is added again in the execution of the first event.…
-
0
votes1
answer113
viewsA: Typeerror: send_email() takes Exactly 1 argument (0 Given)
While trying to create the thread you are invoking the function, while the correct one would just pass the object representing the function. Change: w1 = threading.Thread(target=send_email(),…
-
3
votes2
answers69
viewsA: Program with boolean expressions enters the if block every time
Another way of doing it would be: prefixes = 'JKLMNOPQ' for prefix in prefixes: suffix = 'uack' if prefix in {'Q', 'O'} else 'ack' print(prefix + suffix) See working on Repl.it | Ideone | Github…
-
0
votes2
answers249
viewsA: Python script does not generate chart as expected
You are initiating the list vaplicacao with a value: vaplicacao=[va] While the list vsaque empty start: vsaque=[] As, within the loop, you always add a value in each list, the list vaplicacao at all…
-
2
votes2
answers654
viewsA: Get src attribute content in <img> tag via javascript
As a suggestion, I believe that using an image for this is unnecessary. Several fonts have characters that reproduce the open and closed eye image; the Unicode table itself has the character U+1F441…
-
0
votes1
answer288
viewsA: PHP - Listing directories recursively and finding files
Yes, it is possible, just use the function glob: foreach (glob('D:/**/*.bak') as $path) { echo $path, PHP_EOL; } It will fetch all files that have the extension .bak in any directory within D:/.…
-
0
votes1
answer198
viewsA: Double event on jQuery click
You can try with the function one jQuery. It is similar to the function on, except that the event is removed from the element only its first execution, i.e., for the example below the function in…
-
0
votes1
answer406
viewsA: Variable never reaches zero using Randi
The function randi(x) returns a random number in the set [0, x[, that is, a number between 0 and x-1. In this way, there will come a time when only 1 of life will remain (life = 1) and making…
-
5
votes1
answer2113
viewsA: Use a function variable in another python function
Avoid using global variables unnecessarily. This only harms its application, especially when it needs to be maintained, because a variable can magically change value from one line to the other…
-
3
votes4
answers5062
viewsA: Check empty variable in PHP
If your variable should be a number, do not use empty. Just read what the documentation says: Value Returned Returns FALSE if var exists and is not empty, and does not contain a zeroed value.…
-
1
votes2
answers68
viewsA: Increment in For loop
I could not identify any pattern in the sequence that could facilitate its creation. The closest I came was doing: foreach (range(0, 23) as $i) echo ($i*8 + 1) % 23, ' '; But the way out is: 1 9 17…
-
1
votes1
answer1198
viewsA: Return an array of a function in javascript
What you’re doing is an asynchronous request, so it makes no sense to set returns, since you won’t know how long it will take to get the result - and keep your script locked while waiting is a bad…
-
2
votes1
answer140
viewsA: Python Method resolution order (MRO)
No, it has nothing to do with the method being class, but with the call super().foo() within the method. You can observe the order of name resolution in Python 3.3+, using the function mro of the…
-
2
votes1
answer808
viewsA: How to separate each element from a list, with a String, in a row
Simply change the position of the conditional and use what, in Python, is basically a ternary operator: lista = [x if x % 2 == 0 else 'a' for x in range(10)] The value of x shall be [0, 10[,…
-
12
votes2
answers355
viewsQ: How to create a fallback when importing CSS files?
In How I should work on Bootstrap and Javascript links?, about how to serve the media files, whether via CDN server or local server, it was answered that it is interesting to keep both: initially…
javascriptasked Woss 73,416 -
1
votes2
answers297
viewsA: How to find the most common value within each column of an array using python?
Similarly to what the Vitor Hugo posted in his reply, just calculate the transposed matrix and check the most common element of each line; the logic is exactly what he used, but it is possible to do…
-
3
votes2
answers1192
viewsA: Python matrices - Concatenate
You can use the native function zip: def matrix_union(A, B): for a, b in zip(A, B): yield [*a, *b] The return of the function will be a generator in which each line will be the junction of the lines…
-
5
votes1
answer756
viewsA: How should I work regarding Bootstrap and Javascript links?
The two forms are complementary and both with their respective disadvantages. Ideally, you should always prefer the version that is on the CDN, because, of course, it is on the CDN. A CDN file will…
-
5
votes1
answer562
viewsA: Hidden input fields of html do not come out in $_POST
Your fields Hidden do not own the property name definite: <input type="hidden" id="idEmail" value="<?php echo $_GET["idEmail"]; ?>" /> <input type="hidden" id="adminCli" value="c"…
-
0
votes1
answer53
viewsA: Sort menu by ID
Sorting logic is different from selection logic. If you need to sort by id, then just do ORDER BY id [DESC] - where DESC is optional, present only when you wish to sort in a decreasing way. Already,…
-
0
votes1
answer76
viewsA: Is there any way to reference an Enum inside itself in Python?
There is, but not the way you’re doing it, although it’s not really a problem to create a enumerable from tuples, but the logic itself has gotten pretty strange. Bearing in mind that each value of…
-
3
votes2
answers7328
viewsA: Limiting the number of characters in a Python string
The guy string is iterable in Python and allows you to access its content via Slices. For example, texto[1:5] would return from the first to the fourth character of texto. >>>…
-
1
votes2
answers90
viewsA: sort list c lambda
The problem is that alfabeto.get(i, ord(i)) will return an integer value, whatever the value is in alfabeto or its ord. How do you pass this result to key, it waits for a searchable object; since…
classificationanswered Woss 73,416 -
2
votes1
answer48
viewsA: Find substring with REGEX
You can use the function re.sub to replace based on a regular expression and, if you pass as value to replace a searchable object, the value captured in the regular expression will be replaced by…
-
2
votes5
answers2767
viewsA: HTTP methods in practice
Which method will I use for authentication? To answer what I said and was not addressed in the other answers. Resource of user is different from resource authentication. Imagine that you have the…
-
2
votes2
answers213
viewsA: Validation POST php array
One way to do it is to generate a array associative from the form already relating the data of each record. Something like: <tr> <td><input type="text" name="registros[0][nome]"…
-
3
votes2
answers59
viewsA: Explanation of how loop variable declaration For/In works
Because if you don’t declare, where will you store the content during the loop? The variable needs to exist to receive the value. But it doesn’t have to be necessarily before the loop; it can be…
-
3
votes2
answers329
viewsA: Python: conditions for various symbols
If you need to check if at least one operator is in the word, you can use the function any: if any(simbolo in palavra for simbolo in simbolos): print('Pelo menos um símbolo está na palavra') Or you…
-
1
votes1
answer212
viewsA: What does $@ mean in shell script?
Imagine that the command to be executed will be: $ adiciona_usuario anderson m1nh4_s3nh4 "Anderson Carlos Woss" There will be 3 parameters. The first will be used for the user and the second for the…
shell-scriptanswered Woss 73,416 -
2
votes1
answer530
viewsA: Bootstrap v4.1 - Collapse does not work correctly
The problem is that the event 'shown.bs.collapse' that you are working on is propagating. That is, the event that occurs on Collapse internal will propagate by the parent elements and, consequently,…
-
1
votes1
answer591
viewsA: Object array in Typescript when changing a value the others are changed
See the documentation of Array.prototye.fill: The method fill() fills all array values from the initial index to a final index with a static value. That is, all positions of your array will be…
typescriptanswered Woss 73,416 -
0
votes4
answers725
viewsA: Function that returns the element with more characters from a list
A way to work with multilevel lists, that is, allow you to have lists of lists of lists of lists of... of string, is to represent all these data flat, as if they were only on one level. It is…
-
1
votes2
answers1305
viewsA: How to turn a list into a set in Python?
Realize that you did: print(set(jogador).intersection(computador)) But jogador will be the whole kind, because: jogador = int(input(f'{numero}º número: ')) An integer is not eternal and therefore…
-
1
votes3
answers3331
viewsA: Return the amount of elements repeated in a list
One way is to use the structure collections.Counter: from collections import Counter lista = [4, 2, 1, 6, 1, 4, 4] contador = Counter(lista) repetidos = [ item for item, quantidade in…
-
1
votes1
answer974
viewsA: Write a string list to a file
As commented, the function writelines does not add any separator between the values of the list, so if the intention would be to write a word per line, you need to manually add the character \n. For…
-
2
votes2
answers326
viewsA: I need to make a Python entry by storing it as a list, all in one line
If the values are related to each other, do not store them in different structures, this will only increase the complexity of their application. It will be easier for you to have just a list and…
-
3
votes1
answer1696
viewsA: Does HTTP delete method have body?
Possess, all possess¹. The body is an attribute of an abstraction superior to the entity of the request; i.e., every HTTP request is, like every HTTP response, a message HTTP and any message can be…
-
5
votes2
answers324
viewsA: Singleton pattern in Python
No, not even close. If it were the same thing, when you executed obj2.getConteudo() the message to be displayed should be "hello world", not the default, because you changed the value of this…
-
2
votes1
answer638
viewsA: Take JS Variable value and pass to PHP and send by URL
You don’t even need PHP for this. If the value is already on the page there will be the link, just use JS only. Simple example: const variavel = "SOpt"; const link = document.getElementById('link');…
-
5
votes3
answers183
views -
9
votes3
answers3591
viewsA: How to use "while not in" in Python?
The error is that the function input at all times returns a string and you are checking whether a string belongs to a list of integers. This condition will never be satisfied. print('1' in [0, 1,…
-
1
votes1
answer235
viewsA: Python: Slow code execution and other problems
Just to iterate the given solution, the way you did, calling the method save() inside the repeat loop, you will be saving the disk file multiple times (15 x 1664 = 24.960 times precisely). Read and…
-
4
votes1
answer55
viewsA: What does this variable mean?
It turns out that methods are also attributes of an object. In this case, the event["name"] will have as value the name of an object method entity and when it does: service = getattr(entity,…