Posts by TigerTV.ru • 303 points
8 posts
-
2
votes3
answers72
viewsA: How to manipulate cells from a vector?
A solution def acc(a): s = 0 for i in a: yield i + s s *= 2 s += i vetor = [2, 1, 20, 5, 17, 19, 14, 4, 18] *res, = acc(vetor) print(res) # [2, 3, 25, 35, 82, 166, 327, 644, 1302] or without the…
-
2
votes2
answers192
viewsA: Sum of numbers in a range C++
Recursive function of the tail: // n <= m int somanm(int n, int m) { if (n == m) return n; return somanm(n, m - 1) + m; } another recursive function: // n <= m int somanm(int n, int m) { if (n…
-
2
votes2
answers140
viewsA: I cannot use the value passed in argv in the program call
argv is an arrangement of pointers. Better write: #include <stdio.h> int main (int argc, char *argv []){ if (argc < 2) return 0; if (*argv[1] == 'b'){ printf("Bom dia"); } } or #include…
-
2
votes4
answers197
viewsA: Python, how to calculate the average of a list of 5 in 5 elements?
A solution with list comprehension: lista = [1,2,4,3,7,4,6,5,8,1,9,4,3] r = 5 media = [sum(lista[i:i+r])/len(lista[i:i+r]) for i in range(0,len(lista),r)] print(media) As mentioned @fernandosavio,…
-
2
votes2
answers115
viewsA: Make a sequence of letter combinations start with a specific letter
A solution: from string import ascii_uppercase as au from itertools import product import time bl = "FFF" # begin_letters bn = 11111 # begin number c = [''.join(i) for i in product(au,…
pythonanswered TigerTV.ru 303 -
4
votes4
answers1234
viewsA: Python - Calculate transposed matrix
A solution a = [[1, 2, 3, 4], [4, 6, 7, 9], [4, 3, 2, 1]] *b, = zip(*a) print(b) Exit [(1, 4, 4), (2, 6, 3), (3, 7, 2), (4, 9, 1)]…
-
1
votes2
answers54
viewsA: Take only the first record of each condition
A solution using DISTINCT ON: SELECT DISTINCT ON (id_uni_sching) id_uni_sching, id_sching, dta_sching, sta_sching FROM tabela1 ORDER BY id_uni_sching, dta_sching, sta_sching;…
-
5
votes3
answers114
viewsA: Reading undesirable characters - Python
A solution: import re inp = "João:saiu!! de%$ˆcasa" pattern = "[a-zà-ú]+" output = " ".join(re.findall(pattern, inp, re.I)) print(inp) print(output) or without re.I (ignore case): import re inp =…