def f1(arg): ''' Функция f1 должна вывести отсортированный список профессий без повторений (строки в разном регистре считать равными). Сортировка должна игнорировать регистр. Используйте наработки из предыдущих заданий.''' #raise NotImplemented return sorted(unique(field(arg, 'job-name'), ignore_case=True))
def test_multi_args(self): resp = [i for i in field(self.goods, 'price', 'color')] self.assertEqual(len(resp), 2) for item in resp: self.assertIn('price', item) self.assertIn('color', item) self.assertEqual(len(item), 2)
def test_multi_args_with_one_empty(self): resp = [ i for i in field(self.goods, 'price', 'color', 'non-existent-field') ] self.assertEqual(len(resp), 2) for item in resp: self.assertIn('price', item) self.assertIn('color', item) self.assertNotIn('non-existent-field', item) self.assertEqual(len(item), 2)
def test_multi_args_all_empty(self): goods = [ { 'title': 'Ковер', 'price': 2000, 'color': 'green' }, { 'title': 'Диван для отдыха', 'price': 5300, 'color': 'black' }, ] resp = [i for i in field(goods, 'price-color', 'non-existent-field')] self.assertEqual(len(resp), 0)
def test_multi_args_random_empty(self): goods = [ { 'title': 'Ковер', 'color': 'green' }, { 'title': 'Диван для отдыха', 'price': 5300, 'color': 'black' }, { 'price': 300 }, ] resp = [i for i in field(goods, 'price', 'color')] self.assertEqual(len(resp), 3) for item in resp: if 'price' in item and 'color' in item: self.assertEqual(len(item), 2) elif 'price' in item: self.assertEqual(len(item), 1) elif 'color' in item: self.assertEqual(len(item), 1)
def f1(arg): return sorted(unique([i for i in field(arg, 'job-name')], ignore_case=True), key=lambda x: x.lower())
#!/usr/bin/env python3 from librip.gens import field goods = [{ 'title': 'Ковер', 'price': 2000, 'color': 'green' }, { 'title': 'Диван для отдыха', 'price': 5300, 'color': 'black' }, { 'title': 'Стелаж', 'price': 7000, 'color': 'white' }, { 'title': 'Вешалка для одежды', 'price': 800, 'color': 'white' }] # Реализация задания 1 print([it for it in field(goods, 'title')]) print([it for it in field(goods, 'title', 'price')])
#!/usr/bin/env python3 from librip.gens import field goods = [{ 'title': 'Ковер', 'price': 2000, 'color': 'green' }, { 'title': 'Диван для отдыха', 'price': 5300, 'color': 'black' }, { 'title': 'Стелаж', 'price': 7000, 'color': 'white' }, { 'title': 'Вешалка для одежды', 'price': 800, 'color': 'white' }] print(list(field(goods, None))) print(list(field(goods, 'title'))) print(list(field(goods, 'title', 'price'))) print(list(field(goods, 'title', 'price', 'color'))) print(list(field(goods, 'title', 'price', None, 'color', None)))
def f1(arg): job = list(field(arg, 'job-name')) job = unique(job, ignore_case = True) job = sorted(job) return job
#!/usr/bin/env python3 from librip.gens import field from librip.gens import gen_random goods = [{ 'title': 'Ковер', 'price': 2000, 'color': 'green' }, { 'title': 'Диван для отдыха', 'price': 5300, 'color': 'black' }, { 'title': 'Стелаж', 'price': 7000, 'color': 'white' }, { 'title': 'Вешалка для одежды', 'price': 800, 'color': 'white' }] # Реализация задания 1 print(list(field(goods, 'title'))) print(list(field(goods, 'title', 'price'))) print(list(gen_random(1, 3, 5)))
def f1(arg): #return (sorted(unique(field(arg,"job-name"),ignore_case=True))) return sorted(unique(field(arg, "job-name"), ignore_case=1), key=lambda x:x.lower())
#!/usr/bin/env python3 from librip.gens import field, gen_random goods = [{ 'title': 'Ковер', 'price': 2000, 'color': 'green' }, { 'title': 'Диван для отдыха', 'price': 5300, 'color': 'black' }, { 'title': 'Шкаф', 'price': 20500, 'color': 'red' }, { 'title': 'Вешалка для одежды', 'price': 800, 'color': 'white' }] # Задание 1 print(*('\'' + x + '\'' for x in field(goods, 'title'))) print(*(x for x in field(goods, 'title', 'price'))) print(*(x for x in gen_random(1, 3, 5)))
def f1(arg): return sorted(unique(field(arg, 'job-name'), ignore_case=1), key=lambda x: x.lower())
def f1(): return sorted(list(field(data, 'job-name')))
#!/usr/bin/env python3 from librip.gens import field from librip.gens import gen_random goods = [ { 'title': 'Ковер', 'price': 2000, 'color': 'green' }, { 'title': 'Диван для отдыха', 'price': 5300, 'color': 'black' }, ] # Реализация задания 1 print([x for x in field( goods, 'title', )]) print([x for x in field(goods, 'title', 'color')]) print([x for x in gen_random(1, 3, 5)])
'title': 'Диван для отдыха', 'price': None, 'color': 'black' }, { 'title': 'Стелаж', 'price': 7000, 'color': 'white' }, { 'color': 'red' }, { 'title': 'Нечто' }, { 'title': 'Вешалка для одежды', 'price': 800, 'color': 'white' }] # Реализация задания 1 def print_list(list): for x in range(len(list)): print(list[x], end='') if x != len(list) - 1: print(end=', ') new_items = [] for x in field(goods, 'color1', 'price'): new_items.append(x) print_list(new_items)
def f1(arg): return sorted(unique(field(arg, 'job-name'), ignore_case=True))
def f1(arg): a = field(data, arg) a = Unique(a, x=True) return a.items
'title': 'Ковер', 'price': 2000, 'color': 'green' }, { 'title': 'Диван для отдыха', 'price': 5300, 'color': 'black' }, { 'title': 'Стеллаж', 'price': 7000, 'color': 'white' }, { 'title': 'Шкаф', 'price': None, 'color': 'white' }, # частично None { 'title': None, 'price': None, 'color': None } # все None ] # Реализация задания 1 print("field 1:", list(field(goods, 'title123'))) print("field 2:", list(field(goods, 'title', 'price'))) print("gen_random 1:", list(gen_random(1, 3, 5))) print("gen_random 2:", list(gen_random(1, 3, 5)))
#!/usr/bin/env python3 from librip.gens import field from librip.gens import gen_random goods = [ {'title': 'Ковер', 'price': 2000, 'color': 'green'}, {'title': 'Диван для отдыха', 'price': 5300, 'color': 'black'}, {'title': 'Стелаж', 'price': 7000, 'color': 'white'}, {'title': 'Вешалка для одежды', 'price': 800, 'color': 'white'} ] print(str(field(goods, 'title'))[1:-1]) print(*field(goods, 'title', 'price'), sep=', ') print(*gen_random(2, 5, 7), sep=', ') # Реализация задания 1
from librip import gens goods = [{ 'title': None, 'price': 2000, 'color': 'green' }, { 'title': 'Диван для отдыха', 'price': 5300, 'color': 'black' }, { 'title': 'Стелаж', 'price': 7000, 'color': 'white' }, { 'title': 'Вешалка для одежды', 'price': 800, 'color': 'white' }] for i in gens.field(goods, 'title'): print(i, end='| ') print('') for i in gens.gen_random(1, 10, 12): print(i, end='| ') print('') [print(x) for x in gens.field(goods, 'title')]
def f1(arg): jobs = list(field(arg, "job-name")) jobs = Unique(jobs, ignore_case=True) jobs = sorted(jobs) return jobs
def f1(arg): return list(Unique(list(field(arg, "job-name")), ignore_case=True))
#!/usr/bin/env python3 from librip.gens import field, gen_random goods = [ {'title': 'Ковер', 'price': 2000, 'color': 'green'}, {'title': 'Диван для отдыха', 'price': 5300, 'color': 'black'}, {'title': 'Стелаж', 'price': 7000, 'color': 'white'}, {'title': 'Вешалка для одежды', 'price': 800, 'color': 'white'} ] print([x for x in field(goods, "title")], [x for x in field(goods, "title", "price")], [x for x in gen_random(0, 3, 5)], sep="\n") # Реализация задания 1
def f1(arg): return sorted(list(unique(field(arg, 'job-name'))), key=lambda s: s.lower())
def f1(arg): return sorted( [st for st in Unique(field(arg, 'job-name'), ignore_case=True)], key=lambda x: x.upper())
def f1(arg): return sorted(unique([x for x in field(arg, "job-name")], ignore_case=True), key=str.lower)
#!/usr/bin/env python3 from librip.gens import field from librip.gens import gen_random goods = [ {'title': 'Ковер', 'price': 2000, 'color': 'green'}, {'title': 'Диван для отдыха', 'price': 5300, 'color': 'black'}, {'title': 'Стелаж', 'price': 7000, 'color': 'white'}, {'title': 'Вешалка для одежды', 'price': 800, 'color': 'white'} ] # Реализация задания 1 #print() print(field(goods, 'title', 'price'), gen_random(1, 5, 5)) lst = [1, 3, 5] guard1 = [ x * x for x in lst] guard2 = list(map(lambda x: x * x, lst)) print(guard1); print(guard2);
def f1(arg): return list( sorted(Unique(field(arg, 'job-name'), ignore_case=False), key=lambda x: x.lower()))
#!/usr/bin/env python3 from librip.gens import field from librip.gens import gen_random goods = [{ 'title': 'Ковер', 'price': 2000, 'color': 'green' }, { 'title': 'Диван для отдыха', 'price': 5300, 'color': 'black' }, { 'title': 'Стелаж', 'price': 7000, 'color': 'white' }, { 'title': 'Вешалка для одежды', 'price': 800, 'color': 'white' }] # Реализация задания 1 # for f in field(goods, 'title', 'color', 'price'): print(f) print(', '.join(map(str, field(goods, 'title')))) print() print(', '.join(map(str, gen_random(1, 3, 5))))