Posts by Woss • 73,416 points
1,476 posts
-
1
votes2
answers122
viewsA: Add accented characters within an array
Your problem is basically walking through a string marked. The problem is that PHP, by default, will scroll through the characters at each byte, getting lost in multibyte characters, as in the case…
-
3
votes1
answer33
viewsA: Raspberry Pi lights the wrong led
awnser=raw_input(" >") if awnser==4: led(16) else: led(12) The condition awnser==4 will never be satisfied, because the function raw_input at all times returns a string and Python differentiates…
-
2
votes2
answers59
viewsA: How to ensure that three conditions are met? Is there a better way to do it?
The idea is just to check whether you are fit or not from 3 conditions. For this, instead of creating a string with three values and then check all possibilities, you can use the function all: idade…
-
0
votes1
answer470
viewsA: Transforming elements from a string into a PHP array
If the return of your SQL is the string: $str = '["Elemento1", "Elemento2", "Elemento3", "Elemento4", "Elemento5", "Elemento6"]'; Then just use the function json_decode to generate the array: $arr =…
-
4
votes2
answers1751
viewsA: Medium, Minimum and Maximum in a python dictionary
Dictionaries define an injecting relationship between keys and values, a map, so it makes no sense to be orderly (or better, classifiable). In order to rank the maximum and minimum, you will need to…
-
7
votes2
answers384
viewsA: Can the <link> tag be used outside the <head> tag?
Yes, can be used outside the element <head>, but it depends on the use. To import a CSS file, as mentioned, it is recommended to leave it at the top of the document, inside the element…
-
2
votes1
answer701
viewsA: Calculate the number of even numbers in a tuple recursively
Just check if the value is even by checking the rest of the division by 2. If zero is even; if 1 is odd. When even, you must add 1 plus the number of even numbers in the rest of the tuple; if odd,…
-
4
votes1
answer76
viewsA: Diagonal name display (Up to Down)
The function range(n) will generate a sequence of integers [0, n[, which is not very useful to you in this case. If I understand correctly, you need to print the name entered on the "diagonal",…
-
3
votes2
answers108
viewsA: Order dictionary and display 20 first
If you used the collections.Counter, as suggested in Sort dictionary and add python values, I believe you have not bothered to read the documentation. Before using whichever function is essential…
-
1
votes2
answers268
viewsA: Catch string between bars of a PHP variable
The value you want is what we call the path segment of the URL (English, segment path). For this, the ideal is to treat the URL as a URL through the function parse_url: $url =…
-
2
votes3
answers563
viewsA: Problem keeping quotation marks
To make your code cleaner, you can set the string with single quotes, so the message double quotes will not interfere with the syntax: texto = '"Mensagem entre aspas"' Remember that Python allows…
-
2
votes1
answer192
viewsA: Sort dictionary and add python values
All logic of calculating frequency is already implemented natively in Python at collections.Counter, the only thing you need to do is divide the frequency the word appears in the text by the total…
-
4
votes1
answer4261
viewsA: Limit Python number input 3
Just make a condition: if 0 <= num <= 2000: # Faça algo If you want to ask the user for a new entry while the value is invalid, you will need an infinite loop: while True: try: num =…
-
3
votes2
answers31
viewsA: Problems with number format - Adding characters
If you need to change the number "five and three hundred thousand" in the number "fifty-three thousand" obviously it will not just be formatting, as they are different values. In this very specific…
-
3
votes1
answer47
viewsA: Models in Django is everything in one file?
It is normal? It’s up to you. For small applications, you usually don’t need many files, you can simply put them all together into one. There is a way to leave each model in a file? There is, but…
-
4
votes2
answers937
viewsA: How to save a chart to a PNG image?
The same object pyplot referenced by plt has the method savefig: savefig(fname, dpi=None, facecolor='w', edgecolor='w', orientation='portrait', papertype=None, format=None, transparent=False,…
-
1
votes1
answer1549
viewsA: How to get the last update date of a python file
As discussed in How to check which latest file in a Python folder? you can use the property st_mtime of the archive: from pathlib import Path diretorio = Path('.') arquivo = diretorio/'data.txt'…
-
1
votes2
answers105
viewsA: How to make a console.log on the map?
You need to expand your Arrow Function apart from only one expression in such a way that it is possible to add other: findToOptions(searchValue: string): Observable<any[]> { return…
-
1
votes3
answers122
viewsA: Iteration using "while"
You can use the method str.count to calculate the amount of f in its wake: while True: sequencia = raw_input('Digite uma sequência: ') if sequencia: print('Possui {} faltas na…
-
3
votes3
answers665
viewsA: How to turn content from a file into a dictionary in Python?
If your file is in INI format, having a properly defined header: [config] NAME=Maquina01 ID="MAQ 15478" version=08 You can use the native module configparser from Python to interpret the file:…
-
4
votes1
answer474
viewsA: Opening a URL from Tkinter
Python has the package webbrowser natively. In this module there is defined function open which can be used to open a URL through the user’s default browser. Since you didn’t show us any code, I…
-
5
votes2
answers125
viewsA: Array search, with multiple key relations x value
You just build one array similar to what is in the permissions list and use the function array_search: $A = 'X'; $B = 'Y'; $C = 2; $indice = array_search(compact('A', 'B', 'C'), $permissoes); The…
-
1
votes1
answer164
viewsA: Save fields back to python variables
In accordance with the documentation, the return of fetchone will be a tuple with the values returned from the database. So, to create variables, you can deconstruct the tuple: dias, hora_consulta,…
-
11
votes2
answers327
viewsQ: In PHP, does an array’s internal pointer make up its value?
Let us consider the following array: $a = [1, 2, 3, 4, 5]; As we make $b = $a we create a copy of array, so much so that changes made to one of the arrays will not affect the other. However, I…
-
4
votes4
answers6021
viewsA: How to create a function to find the highest value in a list?
def maior_valor(lista): try: if len(lista) == 0: return None maior = lista[0] for valor in lista: if valor > maior: maior = valor return maior except TypeError: return lista Considerations: Due…
-
3
votes3
answers42
viewsA: How to simplify these two methods?
In addition to creating an auxiliary method that takes the operator as a parameter, as shown in the other answers, you can make use of other magic methods to simplify the logic of your class.…
-
3
votes1
answer45
viewsA: Error while passing variable
You used the fetchAll, that returns a array results. As you are searching for the id, you will always have only one result, causing $nome resemble: $nome = [ 0 => [ 'setor_mapa' => ...,…
-
5
votes2
answers538
viewsA: About the structure of the Sorted function, how does it work?
Usually the function sorted will sort using the list values themselves, comparing them. For example, sorted([-2, 1, 0]) return the list [-2, 0, 1]. The parameter key is responsible for changing the…
-
5
votes2
answers683
viewsA: What is the Declare keyword in PHP for?
In PHP 7 another directive has been added: strict_types. This one I see is quite useful in development because it "undoes" a part of the "mess" of types that PHP has, leaving the developer a little…
-
6
votes2
answers1288
viewsA: What do "re:" and "im:" mean in Rust?
This has no relation to immutable or reusable. Probably at some point in the book a structure similar to: struct Complex { re: f64, im: f64 } Representing a complex number. re represents the real…
-
8
votes2
answers643
viewsA: How does the int function handle the n character?
In accordance with the official documentation: class int([x]) [...] If x is not a number or if base is Given, then x must be a string, bytes, or bytearray instance Representing an integer literal in…
-
7
votes1
answer216
viewsA: Conflict between jquery.js
jQuery has the function jQuery.noConflict to circumvent conflict errors. It was originally made to resolve conflicts with other libraries that also define the object $, but can be used to use…
-
6
votes2
answers1014
viewsA: Find the maximum and minimum number in a list in a string
The problem is that when you share one string you receive a list of strings. The maximum and minimum function will use the same sort logic to identify the highest and lowest value respectively. The…
-
17
votes1
answer3079
viewsA: How does Cubic-Bezier work in CSS Animations?
TL;DR The four parameters define the two control points of the Bézier curve, P1(x1, y1) and P2(x2, y2), to grade 3. cubic-bezier(x1, y1, x2, y2) The Curve of Bézier The Bézier curve is a form of…
-
1
votes1
answer138
viewsA: Python set String where the cursor is
If I understand correctly, you can use the module pyautogui: import pyautogui pyautogui.typewrite('Stack Overflow em Português é demais!') This will simulate keyboard input by typing the text where…
-
1
votes2
answers424
viewsA: How do I calculate the average running time of a function?
An interesting way that Python lets you do it is to create a decorator that manages it for you: def time_statistics(func): def wrapper(*args, **kwargs): start = time.time() result = func(*args,…
-
4
votes1
answer2728
viewsA: Determine recursive Python derivative calculus
One of the ways you can do it is: Receive in a function diff the function to be derived, f, and the derivation order, N; Calculate the derivative g of order 1 of function f; If derivation order N…
-
7
votes1
answer457
viewsA: Codeigniter form_open_multipart, how to use
The problem is you put <button type="button" class="btn btn-success">Cadastrar</button> The element <button> with type="button" does not commit the form. It is most used when you…
-
8
votes2
answers2500
viewsA: How to use a function within another function in python3?
If in function nome() you returns the value read, you will need to store this value in a variable. The variable name that you set within nome() does not exist within intro(). Are different scopes.…
-
7
votes2
answers909
viewsA: Generate float values between -1 and 1
Just read the documentation of what you are using. random.random() Return the next Random floating point number in the range [0.0, 1.0). Translating, returns the next random number with floating…
-
2
votes2
answers480
viewsA: Display matrix in python
First, never go through a Python list with for i in range(len(data)) and then do data[i]. That’s not idiomatic (pythonic). You can just make one for linha in data. data = [ [5, 4, 1, 10, 2], [3, 0,…
-
4
votes1
answer59
viewsA: Create a key/value association from user-informed data
The dictionary defines an injecting relationship between keys and values. In practice, this implies that the key of a dictionary must be unique and related to only one value (otherwise it is not…
-
6
votes2
answers2072
viewsA: how to delete a column in a python csv file
In Python there is the native module csv to work with CSV files. This defines the classes csv.DictReader and csv.DictWriter that facilitate working with the named data. Take an example: import csv…
-
2
votes1
answer1654
viewsA: How to concatenate strings into a list?
The guy string has a method called join who does the job: line1 = '|'.join(row1) It concatenates all values in the list by adding the character between them. The join tends to be more efficient than…
-
3
votes1
answer58
viewsA: How do I call file.Setter using Python to normalize the path name
You are using a property, not defining a static method. Thus, you must create the instance of your class and make the attribution to the property: arquivos = Arquivos() arquivos.file =…
-
6
votes2
answers666
viewsA: Only with CSS is there any way to make a "Toast"? An element that goes up and then click to close it?
You can do something very close using an element that can receive user focus in conjunction with the selector :focus-within CSS. With this selector, you can change the position of the Toast when…
-
3
votes2
answers574
viewsA: Item limit in "foreach"
An alternative is to apply together the classes DirectoryIterator and LimitIterator: $directory = new DirectoryIterator('./data'); $firstFiveFiles = new LimitIterator($directory, 0, 5); foreach…
-
2
votes2
answers128
viewsA: Get answer from callback
Apparently what you want is to generate a new array of strings from the original. If applicable, this is done with the Array.map, not the Array.forEach. I recommend reading each documentation for…
-
6
votes2
answers502
viewsA: Is it possible to use dictionaries inside lists in Python?
Starting with Python version 3.6, you can use dataclasses to structure this type of data. See an example: from dataclasses import dataclass @dataclass class Pet: nome: str tipo: str dono: str pets =…
-
1
votes2
answers633
viewsA: Sort array by a property
As of PHP version 7 Spaceship Operator who assists in this task. What are the "Spaceship Operator" <=> of PHP7? It replaces the conditions (or the ternary) used in the another answer:…