Quiz Catalog

Catalog of quizzes

list_of_tuple = [('bob', 35, 'mgr'), ('sue', 40, 'dev')]

data = list(map((lambda row: row[2]), list_of_tuple))

print(data)
['mgr', 'dev']
  • build-in/map
  • build-in/list
  • list/literal
  • tuple/literal
  • lambda

lst = [True, False]

print(lst[False])
print(lst[lst[False]])
True False
  • boolean/literal
  • list/literal

lst = [(2, 3), (2, 9), (5, 0)]

a = dict(lst)

print(a)
{2: 9, 5: 0}
  • build-in/dict
  • build-in/int
  • list/literal
  • tuple/literal

lst = [3, 1, 2, 4, 1]

sum_of_num = sum(lst, start=2)

print(sum_of_num)
13
  • build-in/sum
  • list/literal

lst = [-4, 0, 2, '', 7, 'a', ' ', -4]

b = list(filter(None, lst))

print(b)
[-4, 2, 7, 'a', ' ', -4]
  • build-in/filter
  • build-in/list
  • list/literal

def check(x):
  if x % 2 == 0:
    return 1


lst = [2, 1, 4, 5, 3]

a = list(filter(check, lst))

print(a)
[2, 4]
  • build-in/filter
  • build-in/list
  • expression/operation/modulo
  • list/literal

lst = [3, 4, 'a', -1]

a = sorted(lst, reverse=True)

print(a)
TypeError: '<' not supported between instances of 'str' and 'int'
  • build-in/sorted
  • list/literal

lst = [2, 5, 5, 1, 3]

itr = iter(lst)

a = next(itr)
b = next(itr)

print(a, b)
2 5
  • build-in/iter
  • build-in/next
  • list/literal

import copy

list1 = [1, 2, 3, [1, 5], ]
list2 = copy.copy(list1)
list2[3][0] = 2
print(list1, list2)
[1, 2, 3, [2, 5]] [1, 2, 3, [2, 5]]
  • object/reference
  • list/literal

a = 1.2
b = a - 0.2
lst = [1.2, 0.2]

print(a, lst[b])
TypeError: list indices must be integers or slices, not float
  • list/literal

lst = [3, 1, 4, 'a', 2]

a = tuple(reversed(lst))

print(a)
(2, 'a', 4, 1, 3)
  • build-in/reversed
  • build-in/tuple
  • list/literal

lst_1 = [2, 5, 9, 0]
lst_2 = [2, 5, 9]

res = min(lst_1, lst_2)

print(res)
[2, 5, 9]
  • build-in/min
  • list/literal

first, second = zip(*[(1, 4), (2, 5), (3, 6)])

print(first, second)
(1, 2, 3) (4, 5, 6)
  • build-in/zip
  • list/literal
  • tuple/literal

if all([2, 0, 4]):
  print("Yes")
else:
  print("No")
No
  • build-in/all
  • list/literal
  • boolean

data = [2, 4, 5, 6, {}]

a = isinstance(data[4], dict)

print(a)
True
  • build-in/isinstance
  • list/literal
  • dict
  • boolean

lst = [1, 2, 3, 4, 5, 6]

a = lst[slice(0, 5, 2)]

print(a)
[1, 3, 5]
  • build-in/slice
  • list/literal

lst = [2, 3, 4, 5]

print(*lst, sep='!', end='?')
2!3!4!5?
  • build-in/print
  • list/literal

data = ['bread', 'milk', 'butter']

enumerate_num = enumerate(data, 1)

print(list(enumerate_num))
Roma
  • build-in/enumerate
  • build-in/list
  • list/literal