Posts by Woss • 73,416 points
1,476 posts
-
3
votes3
answers1598
viewsA: Break lines in a certain Python character space
For this, use the library textwrap who has the function wrap that receives the text and the maximum amount of characters you want per line, returning a list of strings that respect the defined size.…
-
2
votes2
answers807
viewsA: Counting frequencies in a list
When you make an expression like: variavel = funcao() The value that will be assigned to the variable will be the value returned by function. By default Python will return None. That is, if you do…
-
7
votes2
answers1661
viewsA: Laravel: Cannot add Foreign key Constraint
On seeing the documentation, you will see: $table->bigIncrements('id') Incrementing ID using a "big integer" equivalent. That is, a "big integer" column will be created as the primary key. In…
-
6
votes1
answer358
viewsA: How to Manipulate Strings in Python
Yes, but not as directly as C. In C, the character 'a' is stored in memory as the byte 01100001, which in decimal is the number 97. When you add 1 to the value, the computer will add 1 to the byte,…
-
3
votes2
answers84
viewsA: how to get the element from a list based on another list
First, you need to define your filter structure, to define which positions will remain in the list and which will be removed. To do this, simply create a list that has True at positions where the…
-
7
votes1
answer65
viewsA: How to avoid too many Try/except?
The dictionary has a method get which you can take as the second parameter a value that will be returned when the fetched key does not exist. So instead: try: issue_fmt['assignee']['display_name'] =…
-
5
votes2
answers67
viewsA: Unifying values of an array
What you own is something like: $arrayExcluir = [[48609, 48613], [50847], [51709], [47686]]; Then just use the function array_merge to merge all the arrays and, to do so, simply deconstruct the…
-
2
votes1
answer42
viewsA: In-line verification in Python 3
You can even use the operator or to something as you wish because this operator will evaluate the first operand and return it if it is evaluated as true or return the second operand (without…
-
9
votes5
answers5647
viewsA: What is the orthogonality?
In software development the definition of orthogonality is exactly the same as the one used in the mathematical field. In algebra, it is said to be orthogonal when two magnitudes have the scalar (or…
terminologyanswered Woss 73,416 -
2
votes1
answer25
viewsA: Click on button does not work
The problem is that when the code $(".remover").on("click",function(){ console.log("teste"); var linha = $(this).parent().parent(); linha.remove(); }); No element is executed .remover exists in the…
-
6
votes4
answers200
viewsA: Find character succeeded by another character using Regex
The answer is being published only for the purpose of sharing knowledge about the exception launched and its fields and it is not recommended to apply the code here in production. The ultimate and…
-
3
votes3
answers752
viewsA: How to convert int variable to string without deleting zeros?
An integer value has no zeros left; if you need to keep them you should keep their value as string, but if the intention is to do this to validate a month, don’t. Month 02 is the same as month 2, so…
-
1
votes1
answer79
viewsA: Laravel 5.5 Queued?
The option --queued was defined in version 5.0 of Laravel and has already been defined as obsolete in version 5.1, where he went on to create Jobs. From this version all Jobs servants are queued by…
-
2
votes6
answers20131
viewsA: Difference between single and double quotes in PHP
In order to reproduce the comparative performance that many places present by placing the strings with simple quotes as faster, I used the tool Profiling Blackfire in both versions. Version using…
-
1
votes1
answer73
viewsA: remove duplicates by prespetiva of tuples
You cannot use tuples to do the same as you did with the list because the tuples are immutable and thus cannot add new values. To add a new value in the tuple it is necessary to create a new tuple…
-
0
votes2
answers49
viewsA: Inserting information several times
The idea is to always add a line break, '\n', in the output list when a word of VetorUm that belongs to the VetorDois. So just make a loop through VetorUm and check if the word is in VetorDois:…
-
3
votes1
answer48
viewsA: printar json api
This view is the responsibility of the browser when it receives a JSON response from the server. Not all browsers display it like this. For example, when accessing…
-
1
votes1
answer36
viewsA: "Syntax error, Unexpected '&'" when calling exec
Vide documentation: Note: There is no reference signal in function call - only in function settings. The function definitions alone are sufficient to pass the argument by reference. From PHP 5.3.0…
-
5
votes3
answers647
viewsA: Storing latitude and longitude Laravel
The guy decimal is represented as string. If you need the values in their numerical form, just do the cast for that guy: protected $casts = [ 'latitude' => 'float', 'longitude' => 'float', ];…
-
9
votes4
answers11601
viewsA: Set constant in Python
In version 3.8 of Python was added in the module typing the guy Final precisely to represent that a name may not be reallocated, but like all Python type annotation, this does not guarantee at…
-
1
votes1
answer31
viewsA: Does use of frameworks require updates?
Only if you update the versions you use in the application. When you install these frameworks as a dependency on your application you define which exact version you want to use. New versions of…
-
5
votes2
answers118
viewsA: How to remove a class of multiple elements whose names obey a certain criterion
Just go through all the classes of your element and remove those that satisfy your condition: const button = document.querySelector('button') for (let className of [...button.classList]) {…
javascriptanswered Woss 73,416 -
1
votes2
answers164
viewsA: How to modify a Javascript object with the same keys as another array with numbers?
First you must fetch the keys of your object, filter based on the array own and build a new object with the remaining keys. Search for the object keys with Object.keys, Filter with…
-
4
votes1
answer71
viewsQ: What does Typevar’s covariant and contravariant of the Typing module mean?
When using the module typing Python, available in 3.5+ versions, it is possible to define new types using the structure TypeVar. from typing import TypeVar T = TypeVar('T') # Pode ser qualquer tipo…
-
1
votes2
answers638
viewsA: presentation of fractions in javascript
What you can do is implement a class in Javascript that represents a fraction. In the class you can implement methods to sum two fractions and to format the fraction when displayed. For example:…
javascriptanswered Woss 73,416 -
4
votes2
answers60
viewsA: What does it mean when the console returns the function itself?
Because you are explicitly ordering the function to be displayed: console.log(resultado); And not her return. To display the return you need to make the function call: console.log(resultado()); //…
-
8
votes2
answers118
viewsQ: Why does multiple variable assignment create a list when used with the asterisk operator?
Suppose there is a tuple with three values, ('a', 1, 'b'), and you want to assign the first value in one variable and keep the rest in another. For this you can do: a, *b = ('a', 1, 'b') Thus, a…
-
2
votes1
answer79
viewsA: Adding to a list itself. What happens?
Since you are adding the list to it, it will create a recursion. The ellipsis are displayed precisely so that the display is possible, otherwise it would be impossible to define what the output…
-
5
votes1
answer740
viewsA: Python arithmetic progression with decimal numbers
Yes, just use the float. The point is that you don’t need to use the range to calculate all terms of the sequence only to know the nth term. Imagine if the 1,000,000,000th term of the progression is…
python-3.xanswered Woss 73,416 -
6
votes2
answers658
viewsA: What is a Python hash map?
The hash map is an abstraction that is not unique to Python. It is a larger concept, which has been used in several implementations in Python that can be used in the solution of the exercise. How…
-
5
votes2
answers89
viewsA: Regex because only true if put above 5 numbers?
She does not return true only when you put in 5 digits or more, that’s when you put in 4 or more, because what your regular expression defines is "see if there are 4 digits between 0 and 9". Any…
-
1
votes1
answer432
viewsA: Queue - Python (order)
How Python already has the structure collections.deque that allows you to manage a queue, you don’t need to create a class for it. Just use it directly in your function: from typing import List,…
-
7
votes1
answer94
viewsQ: What are the differences between ways of manipulating huge strings with Python?
When it is necessary to work with strings very large it is normal to see approaches that seek to optimize the process in some way. Of the approaches I have seen are using: io.StringIO or io.BytesIO…
-
4
votes1
answer602
viewsA: When to use map() and filter() in Python?
The function map maps; while the filter filtra. They are not equivalent and will never replace each other. In fact it is quite common to use them together (the operations of mapping and filtering,…
-
2
votes3
answers1087
viewsA: Function to return letter frequencies in an array
Because the solution uses a array, arr, as a map, the key being the letter present in string and its value will be the amount it repeats. Initially this array is empty and therefore there will be no…
-
7
votes3
answers158
viewsA: Access a value on an if condition
In the Python 3.8 you can use the assignment Expression: a = int(input('Digite um numero: ')) b = int(input('Digite outro numero: ')) if (result := (a-b)) > 0: print(f'O numero {result} é maior…
-
2
votes1
answer128
viewsA: How do I use the Python range function in this specific case?
def caractere_array(): caractere = [] for i in range(26): caractere.append(chr(65+i)) You create a list varies, sets a repeat loop that will do i range from 0 to 25, inclusive, added in the list the…
-
5
votes1
answer60
viewsQ: Why can’t Ambroses support type notes?
We know that Python, as of version 3.6, supports annotating types in functions and variables, according to the PEP 526 -- Syntax for Variable Annotations and PEP 3107 -- Function Annotations. def…
-
0
votes1
answer66
viewsA: Foreach followed by another Foreach on the same line
It is possible, the syntax is valid, there is no correct or wrong one, so you can use if that’s what you want to do. Just like in C, in PHP it is possible to omit keys when defining a logical block,…
-
2
votes1
answer41
viewsA: Format Python Query
You have only an eternal object, weatherData, and is creating two separate lists, one for the date date = [obj.date for obj in weatherData] and another for values: value = [float(obj.value) for obj…
-
3
votes1
answer193
viewsA: Some Python codes display "__class__" when creating certain classes. What is it for?
All objects in Python have some special fields that are read-only and store information about the same that is used by the language and can be used by the developer. The field __class__ is one of…
-
2
votes1
answer473
views -
11
votes1
answer408
viewsQ: What is a virtual subclass in Python and what are its advantages?
In Python we can implement an abstract class from the module abc and one of the forms is the class inheriting from abc.ABC: from abc import ABC class AbstractClass(ABC): @abstractmethod def…
-
9
votes2
answers269
viewsA: What is the maximum size of a variable of type int in Javascript?
You can get this information through Number.MAX_SAFE_INTEGER. const maxInteger = Number.MAX_SAFE_INTEGER; console.log(`O maior número inteiro é ${maxInteger}`); This value represents the number…
javascriptanswered Woss 73,416 -
7
votes3
answers1161
viewsA: Hanoi Tower - How does this recursive solution work?
This is a case that for you to understand how the function was developed to solve the Hanoi tower you need to consider that there is already a function to solve the Hanoi tower. Confused? No,…
-
17
votes2
answers110
viewsA: What’s the difference of foreach(function) and foreach(function())? Why does the first work and the second does not?
First, let’s simplify the function so you understand better, without changing your behavior. The native function console.log displays a log message in the browser console and will never return any…
javascriptanswered Woss 73,416 -
0
votes2
answers132
viewsA: Error in a Function with callback
The solution is not to change the functions to finish if callback is not defined. In this context it is to treat the symptoms without treating the cause. In some places in the country they call it…
-
2
votes1
answer54
viewsA: HTML PHP concatenation
The error is syntax. Do: echo "<option value='".$dadosano['Year']."' ". isset($_GET['ano']) && $_GET['ano']== $dadosano['Year']?' selected="selected"' : ' ' ; " > ".$dadosano['Year'].…
-
2
votes1
answer60
viewsQ: What is a prolyfill?
We already know what a polyfill (What is Polyfill?), but what is a prolyfill? Is there any relationship between him and himself polyfill, since the names are so similar? I saw the term by chance in…
terminologyasked Woss 73,416 -
1
votes2
answers123
viewsA: Concatenate variable with another PHP variable
Instead of concatenating into the name, use the value of i as an index: Tubo 1 Nome: <input type="text" name="tubo[0]"> Largura: <input type="text" name="largura[0]"> Tubo 2 Nome:…