Posts by Augusto Vasques • 15,321 points
571 posts
-
1
votes2
answers403
viewsA: Compare matrix values and add them to another (python)
Running the question code: matrixOne = [ [ 1, 12, 45], [58, 524, 78], [ 1, 2, 3], [45, 456, 8]] matrixTwo = [ [ 0, 1, 2], [85, 1, 74], [27, 63, 21], [25, 47, 962]] #Inicializa a lista com todas as…
-
1
votes4
answers84
viewsA: Error when using index to pick up a specific index
num = [] #Inicia a lista de coleta de dados. print('Digite 5 valores.') for c in range(1, 6): #Iterando em c pelos números de 1 a 5... while(True): #...inicia um laço de coleta de dado... try:…
pythonanswered Augusto Vasques 15,321 -
1
votes2
answers44
viewsA: C# - Adding indices from an array and filtering for common results
If the numbers are whole and have up to two digits you can extract the drive by calculating the rest of the number division by 10 using the operator % and extract the dozen from that number by just…
-
0
votes1
answer34
viewsA: How to "zoom" a file into another file in visual studio code
If you want to join the contents of multiple text files in memory use a text stream io.StringIO(). The content of io.StringIO() may be written with the inherited method io.TextIOBase.write() or with…
-
2
votes2
answers89
viewsA: Balancing parentheses, how to check if they are in the correct position?
As indicated in comments you can use a stack to test the balancing of parentheses of a sentence. The mechanism is simple, take a string as input and iterate by its characters every time: find an…
javaanswered Augusto Vasques 15,321 -
0
votes2
answers101
viewsA: HOW DO I SELECT A DIV WITH PHP?
One possibility is to separate the style of the markup in a CSS then to decide which <div> color with what color. div { height: 100px; width: 500px; margin-bottom: 5px; } .gray {…
-
0
votes2
answers45
viewsA: I need to count a number of specific numbers per column in a matrix
#Presumindo que esse código só será usado em matrizes quadradas mat = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 1, 0, 0, 0, 0, 0, 0], [0, 0, 1, 1, 1, 0, 0, 0, 0, 0], [0, 1, 1, 1, 1, 1, 0, 0, 0, 0],…
-
3
votes3
answers220
viewsA: How to popular a dynamically key and value dictionary?
By following his reasoning it is still possible to arrive at the intended result. What your code lacked was just enumerating the list of squares obtained and building the dictionary on top of that…
-
1
votes1
answer45
viewsA: Logical operators indicating a range between numbers
Answering your question, not the syntax you used is not valid Binary Logic Operators are normally used with boolean values and return a boolean. In your first condition for example:…
-
1
votes1
answer56
viewsA: How to take specific values and sets in JSON
One possibility is to iterate the object and work only for the properties that begin with badge_ and in an auxiliary object cataloguing the information: const obj = { "navigator.zoom.in": "Zoom +",…
-
1
votes2
answers100
viewsA: Problem with Javascript date comparison
It should be noted that the library Moment js. in his documentation discourages developers from including Moment js. in new projects. In the library documentation the reasons for this are given. As…
-
1
votes4
answers82
viewsA: How do I create a list for possible answers in python?
If you want to test if an element is contained in a sequence use the operator in. x in s returns True if x is a member of s, otherwise returns False. str.lower() returns a copy of the string in…
-
2
votes2
answers54
viewsA: Map array and include ID items using MAP and FILTER
It also has the imperative algorithm that scans the array first options creating a catalog opts whose key is options.question_id and the value is an array of references to the options whose property…
-
5
votes3
answers141
viewsA: Shouldn’t Python none be semantically equal to SQL Null?
This behavior occurs because the language was defined like this. In the official language documentation Data Template: Special Method Names is written: A class can implement certain operations that…
-
0
votes3
answers248
viewsA: Regex - take only the first occurrence of a word in Python?
Due to the lack of clarity of the question, it can be interpreted in the following ways: How to know if a word is present in a text? How to get index of the first occurrence of a word in a text? How…
-
3
votes2
answers65
viewsA: Print an Array in <li> line by line with javascript
Another alternative is to use the DOM HTML which is a structured representation of the document providing methods that allow changing the structure, style and content of the document. In this case…
-
2
votes2
answers85
viewsA: Javascript regex schedules
I think you have focused too much on regex and content separators that have lost the focus of your problem that is interpreting the text. Actually the problem doesn’t even need to be solved with…
-
3
votes3
answers1317
viewsA: Remove duplicate values from an array - php
A functional variation of accepted answer: <?php $arr = ['2015', '2015', '2012', '2013', '2014', '2014', '2016']; $res = array_keys(array_filter(array_count_values($arr), function($v){ return $v…
-
2
votes2
answers325
viewsA: Transforming date object into datetime (year month day) python
I’ll make a modification to the reply from Paulo Marques because I agree that the fact that the months are shortened in capital is a problem to get the solution. But operating systems provide an…
-
0
votes2
answers73
viewsA: how to print words with 7 or more than 7 letters in python
If you want to filter a sequence by one criterion, use the built-in function filter() who according to his documentation: filter(function, iterable) Build an iterator from the iterable elements for…
pythonanswered Augusto Vasques 15,321 -
-1
votes1
answer82
viewsA: I want to return the exact same words but I don’t know how to do it
Assuming that the words in the text file to be analyzed will be separated by spaces, any other scorer should be included along with the words and the search will be insensitive to the letter box,…
-
1
votes2
answers88
viewsA: Django/Python primary key generator with low collision risk and good performance
An alternative is to solve the problem in SQL by defining a new sequence generator with CREATE SEQUENCE and share it among the tables thus creating each insert a new unique primary key with…
-
1
votes1
answer82
viewsA: How to pass multiple files with click python?
I did it in my head because I’m not installing the module click in my system. Test the examples.... The standard Python library includes the module the - Various operating system interfaces, which…
-
2
votes2
answers88
viewsA: Replacing Nan values with the subsequent not Nan of another column
One possibility is to create a dictionary group from the data frame df where keys are the values without duplicates of the column base and the respective key values are a dictionary pointing to the…
-
1
votes4
answers486
viewsA: How would an algorithm work to prevent attempts to trick word blocks (strings)?
It is not a definitive solution because I believe when it comes to Unicode such a solution does not exist. It is possible to restrict to some degree the user’s possibilities of entering character…
-
3
votes5
answers120
viewsA: Merging an array with an object array
Another alternative would be to index each element of the array apis for his id and use each value of applications.apis key to this index. let apis = [ {id: "1", name: "api 1"}, {id: "2", name: "api…
-
2
votes1
answer60
viewsA: Python3: Error in function that has dictionary
Fixing up your code: meses = { "01":"janeiro", "02":"fevereiro", "03":"março", "04":"abril", "05":"maio", "06":"junho", "07":"julho", "08":"agosto", "09":"setembro", "10":"outubro", "11":"novembro",…
pythonanswered Augusto Vasques 15,321 -
3
votes4
answers197
viewsA: Python, how to calculate the average of a list of 5 in 5 elements?
One possibility is to create a generator splitting an iterable into portions and calculating individually the averages for these portions. lista = [1,2,4,3,7,4,6,5,8,1,9,4,3] def chunk(iteravel, n):…
-
2
votes1
answer58
viewsA: How to get all possibilities from an incomplete string
One of several possibilities would be to convert your character string into a class instance ArrayObject create some iterators with the method Arrayobject::getIterator() and iterate them in string…
-
4
votes2
answers65
viewsA: How to take more than one property in a Javascript object array using unstructuring
Just complementing, there is also the for iteration and structuring which is a variation of the declaration for...of who travels iterative objects structuring its elements: const objArr = [ { 'x':…
javascriptanswered Augusto Vasques 15,321 -
2
votes1
answer53
viewsA: SWITCH CASE is not working as expected
According to the documentation of the term conditional switch the optional instruction break associated with each case ensures that the program gets out of parole switch as soon as the corresponding…
javascriptanswered Augusto Vasques 15,321 -
1
votes2
answers201
viewsA: Function to check if one number is divisible by another
The equality operator == checks if your two operands are equal, returning a result boolean, true or false. So no need to test the remnant to print strings with the results. When a statement return…
javascriptanswered Augusto Vasques 15,321 -
0
votes1
answer53
viewsA: Bring bank result and put in a list to use with variables
Interpreting the comments attached to the question... Take a look at the image, in the line above special variables: Your list consists of a tuple of values. If this query returns only a single line…
-
0
votes2
answers73
viewsA: How can I get an Array’s Index number?
With Array.prototype.map() build a Array the indices of the arr whose property value day be equal to 5 and for the other values complete with null. From the resulting array remove entries null with…
-
2
votes2
answers75
viewsA: Concatenate two arrays according to their respective indices
You can merge two arrays of the same length using the method Array.prototype.map() to create an array the element n is a string composed of elements n of L1 and L2. l1 = ["a", "c", "e", "g"] l2 =…
-
0
votes2
answers58
viewsA: Insert values into an array with dimensions defined from a loop
Many of the problems presented here on the site involving numpy and pandas can be solved in reading the data, thus avoiding unnecessary processing. So sometimes Aps are asked for code and data…
-
2
votes2
answers52
viewsA: Add element based on array comparison
Making a change in array nomenclature watched_video for watches and assuming that the ids in the arrays videos and watches are unique it is possible to create an instance of Set through the method…
-
6
votes3
answers110
viewsA: How to "flatten" a list of lists of integers?
To get the concatenated output of an iterable use the method chain.from_iterable() available in the module itertools. from itertools import chain d = [[1],[2],[3],[3]]…
-
2
votes2
answers64
viewsA: Bug when adding elements to the list and transforming it into a string
In addition to the already explained iteration loop... for i in range(0, len(char) - 1): ...which should be modified to... for i in range(0, len(word) - 1): ... your code is disproportionately…
-
0
votes2
answers6230
viewsA: javascript multidimensional array
In modern browsers and assuming that both arrays are aligned in both content and structure, the method can be used Array.prototype.flat(), creating a new array by concatenating all elements of the…
-
1
votes2
answers115
viewsA: Limit decimal places
You can round the value to a certain precision of decimal digits with round() and format the output as a fixed point decimal with the number of decimal places desired: from random import uniform def…
-
2
votes3
answers253
viewsA: How to resolve "Valueerror: max() Arg is an Empty Sequence" error when the list is empty?
See the algorithm of your code: Leia o número de entradas e coloque em n Inicialize a lista de velocidades listaVelocidade Itere sobre o número de entradas... Leia uma velocidade Inicialize a lista…
-
2
votes1
answer50
viewsA: When passed by class, numbers do not come out random
This behavior occurs because you have defined a class variable random as the value returned by rd.randrange(-1000, 1000) that this value will be the same for all instances and how only one call is…
-
1
votes2
answers228
viewsA: Create shortcut with python
The code below should run with administrative privileges. If the question is how to get a python script to create a link from you and send it into the global startup folder on windows OS: first your…
-
5
votes3
answers114
viewsA: Reading undesirable characters - Python
It is also possible to remove unwanted characters without using regular expressions. The class str contains the method str.translate() which returns a copy of the string in which each character was…
-
4
votes5
answers287
viewsA: How to go through an array of objects, add specific properties and unify those objects where it has a specific property equal to another?
Still on the subject Map another approach may be used. Make it an instance of Map an index for the elements of Array novoLista which will initially be populated with a copy of the first object in…
javascriptanswered Augusto Vasques 15,321 -
5
votes3
answers358
viewsA: How to generate random hexadecimal colors with Javascript?
To title of curiosity it is also possible to use the Encryption API to generate random numbers. Unlike other encryption API methods, the method RandomSource.getRandomValues() allows to obtain random…
-
0
votes3
answers129
viewsA: Catch internal IP via Python (Router)
Create an underlying process with the class Popen to execute the command line: $ hostname -I Use the method Popen.communicate to return STDOUT. import subprocess #O argumento stdout=subprocess.PIPE…
-
2
votes3
answers52
viewsA: Fill each value of an input with a string variable character
Create an array with ids of the target elements and the itere by the method Array.prototype.forEach() with the callback parameters v for value and i for the iterated element index. With…
-
0
votes2
answers88
viewsA: How to print a decimal value with comma ex: 75.0 would be 7.5?
Convert the numeric value to its equivalent string representation using a specified format with the method Single.ToString(string format, IFormatProvider provider) where: format is a Standard…