Posts by Woss • 73,416 points
1,476 posts
-
5
votes1
answer144
viewsA: Mount two-dimensional PHP array
If you’re going to do this in PHP, just use array_map: $disciplinas = ['x', 'y']; $professores = ['1', '2']; $resultado = array_map(function ($disciplina, $professor) { return compact('disciplina',…
-
4
votes2
answers66
viewsA: Reading an array 2 times
I would recommend you refactor your code. If it is reusable, it could very well be set in a function. In that case, just do: foreach ($teste as $c) { echo foo($c), foo($c); } But if you want to get…
-
1
votes1
answer43
viewsA: Averages of elements in various lists
If you have a list of lists: lista1 = [154,12,998,147] lista2 = [897,123,998,59877] lista3 = [3,789,111,555,699] listas = [lista1, lista2, lista3] You can create a list of the first elements by…
-
1
votes3
answers82
viewsA: Receive result from an ajax as return
The function ajax has as return an object jqXHR which has a method done. That is, just return this object and use the method when you need the request reply. const request = function () { return…
-
2
votes1
answer297
viewsA: How to start the Materialize Chips component with predefined values?
Initializing the field before entering the data You are initiating the field with $('.chips').chips(); before entering the values, this way Materialize will not recognize the values you add later.…
-
4
votes1
answer679
viewsA: Filter elements from a tuple based on a value in a given index
If you have a tuple in the shape valores = (('Maria', 38), ('Miguel', 17), ('Tiago', 18), ('Sara', 19)) You can list items that have the second value less than 18 as follows: menores = tuple(it for…
-
7
votes1
answer90
viewsA: How to return Python value series
To read a file and go through the lines you can use the function open with the context manager defined by with: with open('arquivo.txt') as arquivo: for linha in arquivo: print(linha) As you need to…
-
1
votes1
answer169
viewsA: How do I pass two variables to the onclick parameter?
In doubt do not concatenate, interpole (or format) a string: echo sprintf('<button onclick="deleteVaga(%d, \'%s\')">...</button>', $id, $cidade); Interpolating could stay: echo…
-
3
votes1
answer577
viewsA: Timefield presentation format in Django
In Django there is the filter in date in the template you can use to format the date: {% for obj in objs %} <h1>{{ obj.hora_passagem|date:'H:i:s:u' }}</h1> {% endfor %} This for a model…
-
3
votes3
answers241
viewsA: Remove elements from a Python Stop List
Python has, in the package itertools, the function compress, that remove of an eternal object the values according to the value of another eternal. def compress(data, selectors): #…
-
4
votes2
answers2443
viewsA: How to add the main diagonal of a python matrix?
In Python there is no proper function for this, but implementing it is quite trivial. A square matrix n x n can be represented as: | (1, 1) (1, 2) (1, 3) ... (1, n) | | (2, 1) (2, 2) (2, 3) ... (2,…
-
4
votes1
answer107
viewsA: How to paint multiple page elements by clicking and dragging the mouse?
In a very trivial way, without analyzing all your code, you can create a variable clicado, boolean type, which will be true while the mouse is pressed. In the event mousedown of its elements you…
-
1
votes1
answer14386
viewsA: Typeerror: string indices must be integers - PYTHON
According to your commenting, the JSON you receive resembles: { "lists": [ { "id": "", "web_id": "", "name": "", "contact": { "company": "", "address1": "", "address2": "", "city": "", "state":,…
-
4
votes1
answer42
viewsA: How to store various user read values?
You can use a list. notas = [] aluno = int(input('Qual o numero de alunos ? ')) for i in range(aluno): nota = float(input('Insira a nota de cada um dos alunos: ')) notas.append(nota) And to…
-
3
votes1
answer133
viewsA: add number and delete n in python
First problem is that the first line of your file has no data but a header. You even try to handle it by replacing it with a string empty, but soon after you try to convert the value to integer.…
-
0
votes2
answers67
viewsA: How to relate two lists, obtaining the value of one through the maximum of the other?
Your problem can be solved by using the method index of the list, which will find the index where the value is inside it. For example, in the list lista = [1, 2, 3, 4], the result of lista.index(3)…
-
5
votes3
answers1808
viewsA: When should I use "Return" or "print" in a function?
It is not the same thing. In your example it seems to be, but it is because it is not a good example. If you dig a little deeper, you’ll see that when used print, although the correct value is…
-
10
votes2
answers102
viewsA: Why should descriptors instances in Python be class attributes?
As commented on in What is the function of Python descriptors? there is a call order that the interpreter executes when you do g.attr. Like g, in this case, it is an instance, the interpreter will…
-
2
votes1
answer128
viewsA: Use PHP array and bring results in multiple rows
The problem is that you are overwriting the variable $todos inside your side, discarding the old values: $id = 3; foreach($_POST['form']['clima'] as $clima){ $todos = '('.$id.','.$clima.')'; //…
-
9
votes1
answer676
views -
3
votes2
answers75
viewsA: Withdraw repeated
As commented, you can replace the logic of the internal repetition loop by the method call includes of array: const numbers = [10, 20, 30, 40, 50]; for (let i = 0; i <= 50; i++) { let no =…
-
0
votes1
answer224
viewsA: Filter an object array according to field
Just use the function array_filter to filter by the records you want. // Busca-se todos os registros $total_tipo = $this->chamado->contagem('tipo'); // Filtra os do tipo 1 $tipo_1 =…
-
2
votes1
answer50
viewsA: How to associate a set of words to a "do_" method of the Cmd class?
You can also use the method cmd.precmd, that according to documentation: Cmd.precmd(line) Hook method executed just before the command line line is Interpreted, but after the input prompt is…
-
1
votes3
answers85
viewsA: Repeat if again when validation fails
I have several considerations regarding your code: ConvInicial = str(input('Você: ')) if ConvInicial == 'Não estou passando bem' or ConvInicial == 'Estou com dor' or ConvInicial == 'Preciso de…
-
1
votes3
answers105
viewsA: Error on average of students
If you are using Python 3.6 or higher, you can use f-string: resultado = 'APROVADO' if media > 6 else 'REPROVADO' print(f'O aluno de matricula {matricula} foi {resultado} com a média {media}')…
-
7
votes3
answers9053
viewsA: Multiplying terms from the list
There’s no proper function for it, but there are ways that make it possible for you not to have to do everything by hand. One of the simplest ways is to combine the use of functions functools.reduce…
-
2
votes1
answer441
viewsA: Pick up current PHP week days
You can do the following: $segunda = date('d/m/Y', strtotime('monday this week')); // 15/10/2018 $sexta = date('d/m/Y', strtotime('friday this week')); // 19/10/2018…
-
0
votes1
answer52
viewsA: Put Which Letters Repeat Most and In Order
The class Counter basically iterates on the string and with each character it increases the value in the dictionary: texto = 'anderson carlos woss' quantidade = {} for caractere in texto:…
-
7
votes4
answers701
viewsA: How to create and use custom events
If the idea is to trigger the event myClick whenever there is a click, you can do the following: const myClick = new Event('myClick'); document.addEventListener('click', event => {…
-
8
votes3
answers645
viewsA: With CSS to cut text? Type a cut text effect or broken font?
It is also possible through the property clip-path CSS. The point is to do the clip inverted between the elements before and after. h1 { font-size: 5rem; } [slashed] { text-transform: uppercase;…
-
10
votes2
answers1223
viewsA: What is a nodeList object in Javascript?
NodeList is an internal Javascript class that has the following interface: [Exposed=Window] interface NodeList { getter Node? item(unsigned long index); readonly attribute unsigned long length;…
javascriptanswered Woss 73,416 -
1
votes3
answers316
viewsA: Exercise changing last element
You can use the method str.rpartition that will divide the string in the last occurrence of the separator, returning a tuple of 3 values: the part of the string before the division, the separator…
-
1
votes2
answers3618
viewsA: Grab specific column csv with python
Just use the module itself csv imported in your example, using the DictReader, for example: def get_column_of_csv(filename, column): with open(filename) as stream: reader = csv.DictReader(stream)…
-
1
votes3
answers1479
viewsA: Show input value by clicking the button
Several things to be corrected: You treated event click twice, both in the attribute onclick how much element in jQuery with the function on, just one of them; You have accessed the attribute value…
-
6
votes3
answers4175
viewsA: How to change a PHP array’s key
It seems simple, but it’s not that trivial. The answer to your question is: is not possible. That said you would ask me "how is it not possible if the other answers showed how to do it?" and I would…
-
8
votes4
answers3500
viewsA: How to increase the space between text and underline in CSS?
Is not possible. Browsers take due care to use only the spacing between the baseline and the beardline of the text precisely so as not to change its dimensions (space called descend). So much so…
-
4
votes2
answers672
viewsA: How to make a reflected text with CSS ? (like a mirrored text)
Two distinct elements can break the HTML semantics as it will insert content redundancy into the document. One of the elements <h1> would be merely aesthetic and adds nothing to the content,…
-
4
votes4
answers658
viewsA: Debug showing variable name and value?
As commented, an option to display the debug of variables is using the module inspect. With the help of function inspect.stack you can verify the context from which the function was executed and…
-
5
votes3
answers856
viewsA: Validate input without variable
Complementing the response of Maniero... Python has a memory temporary, to stack, which is used to execute your code. Whenever you call a function, the return will be automatically stored in the…
-
1
votes1
answer563
viewsA: Runtime error - question
The input file contains two rows of data. Then you should do only two input readings and divide the values: entrada = input().split() codigo_1 = int(entrada[0]) quantidade_1 = int(entrada[1])…
-
15
votes3
answers356
viewsA: Why is it possible to change an array or object value from within a constant?
As an old teacher of mine would say: Don’t confuse "archipelago of Fernando de Noronha" with "skinny marijuana smoker". They may sound alike, but they’re completely different. He said that basically…
-
8
votes2
answers111
viewsA: What is the name of this structure in Python?
Is known for f-string, a new syntax added to Python in version 3.6 to perform interpolation of strings. It must necessarily have the prefix f and all groups between keys, {var}, shall be analysed…
-
1
votes1
answer56
viewsA: Show on the screen the following operation with the tuple Tu: (ab)+(bc)+(cd)+(de)/e
There are several ambiguities in the question that directly affect the solution. The first is that we have no way of knowing for sure if the value ab must be the concatenation of values a and b,…
-
2
votes2
answers770
viewsA: What is the difference between namedtuple and Namedtuple?
For all practical purposes, they are the same. Indeed, the very implementation of typing.NamedTuple uses the structure internally collections.namedtuple for all tuple logic, adding some fields to…
-
5
votes1
answer349
viewsQ: What is Reduced Motion Media Query?
I recently saw that there is the concept of Reduced Motion Media Query in the CSS, which apparently is a response to the animation settings in the client’s browser and is used in code primarily by…
-
8
votes3
answers3029
viewsA: How to calculate perfect numbers quickly?
There is a direct relationship between the perfect numbers and the prime numbers of Mersenne. A prime number of Mersenne is nothing more than a prime number that can be written in the form Mn = 2n -…
-
5
votes1
answer2037
viewsA: Calculate sine by Taylor series expansion
I really could not understand your code, I found quite confusing the names of the variables, making it very difficult to understand what is each thing within the code. If you notice, the given…
-
11
votes8
answers309745
viewsA: Reduce image size and maintain CSS aspect ratio
In CSS there is still the property object-fit defining how an object should behave towards an element with defined dimensions. For example, let’s consider a square element with 100 px of side and a…
-
3
votes1
answer275
viewsA: Problems with the 'continue' or 'while' command in Python
and as far as I know, in python, everything other than 0 is true Your premise is wrong. In Python, any non-zero number will be considered a true value, but not necessarily equal to True. Are the…
-
3
votes3
answers78
viewsA: How to add class to all read except the one that was clicked
There is still the method siblings of the jQuery that returns the sibling elements, that is, elements that are on the same level of the DOM as the element in question. Optionally it is possible to…