xxxxxxxxxx
import re
def convert(placa):
char = ['A','B','C','D','E','F','G','H','I','J']
regex = '[A-Z]{3}[0-9]{4}'
if(re.match(regex, placa)):
placalist = list(placa)
posicao = int(placalist[4])
placalist[4] = char[posicao]
placaMercosul = ''.join(placalist)
return placaMercosul
else:
return placa
xxxxxxxxxx
>>> import js2py
>>> f = js2py.eval_js( "function $(a) {return a + arguments[1]}" )
>>> f
function $(a) { [python code] }
>>> f(1, 2, 3)
3
xxxxxxxxxx
n = 0
while n <= 0:
n = int(input("Enter the number of lines: "))
for i in range(1, n+1):
print('*' * i)
xxxxxxxxxx
n = 0
while n <= 0:
n = int(input("Enter the number of lines: "))
for i in range(1, n+1):
for j in range(1, i+1):
print('*', end='')
print()
xxxxxxxxxx
def choose_best_sum(t, k, ls):
most = 0
for i in range(len(ls)-1):
addN = 0
if i +k > len(ls) - 1:
break
for j in range(i,i+k-1):
addN += ls[j]
for p in range(i+k-1,len(ls)-1):
addN += ls[p]
if addN > most and addN <= t:
most = addN
addN -= ls[p]
else:
addN -= ls[p]
if most == 0:
return None
return most
xxxxxxxxxx
if g == 0:
return [1] * len(originCities)
if g >= n:
return [0] * len(originCities)
components = {i: i for i in range(g + 1, n + 1)}
for candidate in range(g + 1, n + 1):
current = [t * candidate for t in range(1, n // candidate + 1)]
current_components = [components[e] for e in current]
minone = min(current_components)
for curr in current:
components[curr] = minone
res = []
for k in range(len(originCities)):
origin, destination = originCities[k], destinationCities[k]
if origin > g and destination > g and components[origin] == components[destination]:
res.append(1)
else:
res.append(0)
return res
xxxxxxxxxx
l=int(input())
arr=list(map(int, input().split()))
arr=list(set(arr))
length_list=len(arr)
arr.sort()
#print("set = ",arr)
#print("length of set: ",length_list)
print(arr[length_list-2])
xxxxxxxxxx
def ArrayMatching(strArr):
x = [int(i) for i in strArr[0][1:-1].split(',')]
y = [int(i) for i in strArr[1][1:-1].split(',')]
sums = []
for i in range(max(len(x), len(y))):
total = 0
if i < len(x):
total += x[i]
if i < len(y):
total += y[i]
sums.append(str(total))
return '-'.join(sums)
xxxxxxxxxx
def StringPeriods (s):
for i in range (int (len (s)/2), 0,-1):
a = s[i] count = 2
b = "
while len (b)
b = a * count
if b == s:
return a
len(s):
count += 1
return -1