conf = {
"database": {
"username": "RadoRado",
"password": "password123",
"host": "localhost",
"database_name": "students"
},
"email": {
"SMTP": "giga.superhosting.bg",
"port": 223,
},
"users": ["Ivo", "Maria", "Rado"]
}
>>> conf["database"]
{'username': 'RadoRado', 'host': 'localhost'...
>>> conf["database"]["username"]
'RadoRado'
>>> conf["email"]["SMTP"]
'giga.superhosting.bg'
>>> conf["users"][0]
'Ivo'
from math import sqrt
def area(a, b, c):
p = (a + b + c) / 2
pa = p - a
pb = p - b
pc = p - c
return sqrt(p * pa * pb * pc)
def member(x, xs):
found = False
for memb in xs:
if x == memb:
found = True
break
return found
def prime_in_list(numbers):
found = False
for number in numbers:
if is_prime(number):
found = True
break
return found
def prime_in_list(numbers):
count = 0
for number in numbers:
if is_prime(number):
count += 1
return count
def max(items):
current_max = items[0]
for item in items:
if item > current_max:
current_max = item
return current_max
def hash_them(keys, values):
result = {}
index = 0
for key in keys:
if index < len(values):
result[key] = values[index]
else:
result[key] = None
index += 1
return result
[0, 0, 1, 2, -2, 5]
[1, 2, 3, 4, 5, 6, 7, 8]
def zero_neighbours(numbers):
index = 0
for number in numbers:
if index < len(numbers) - 1:
neighbour = numbers[index + 1]
if number + neighbour == 0:
return True
index += 1
return False
[1, 2, 3, -1, 5, 10, -10, 20]
example = [1, 2, 3]
for x in example:
for y in example:
print(x, y)
example = [1, 2, 3]
n = len(example)
for i in range(0, n):
for j in range(i, n):
x = example[i]
y = example[j]
print(x, y)
example = [1, 2, 3]
n = len(example)
for i in range(0, n):
for j in range(i + 1, n):
x = example[i]
y = example[j]
print(x, y)
def zero_pairs(numbers):
for x in numbers:
for y in numbers:
if x + y == 0:
return True
return False
["Ivan", "Maria"], ["Python", "Django"]
["Ivan", "Maria"], ["Python", "Django"]
items1 = ["Ivan", "Maria"]
items2 = ["Python", "Django"]
for x in items1:
for y in items2:
print(x, y)
[ [1, 2, 3],
[4, 5, 6],
[7, 8, 9] ]
[ [1, 2],
[4, 5],
[6, 7],
[8, 9] ]
[ [1, 2, 3, 4] ]
matr = [ [1, 2, 3],
[4, 5, 6],
[7, 8, 9] ]
print(matr[0][0]) # 1
print(matr[0][1]) # 2
print(matr[1][2]) # 6
matr = [ [1, 2, 3],
[4, 5, 6],
[7, 8, 9] ]
for row in matr:
for element in row:
print(element)
matr = [ [1, 2, 3],
[4, 5, 6],
[7, 8, 9] ]
n = len(matr)
m = len(matr[0])
for row_index in range(0, n)
for col_index in range(0, m):
element = matr[row_index][col_index]
print(element)