Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # L1 (1)
- # def sum_list(list):
- # sum = 0
- # for x in list:
- # sum = sum + x
- # return sum
- #
- # my_list = [1,2,3,4]
- # print(sum_list(my_list))
- # L2 (2)
- # def multiply_list(list):
- # multiplication = 1
- # for x in list:
- # multiplication *= x
- # return multiplication
- #
- # my_list = [1,2,3,4]
- # print(multiply_list(my_list))
- # L3 (3)
- # def largest_number(list):
- # list.sort()
- # return list[-1]
- #
- # my_list = [3,1,4,2]
- # print(largest_number(my_list))
- # 4
- '''
- my_list = [3,1,4,2]
- my_list.sort()
- smallest_number = my_list[0]
- print(smallest_number)
- '''
- # L4 (5)
- # def count_specific_str(list):
- # counter = 0
- # for x in list:
- # if len(x) >= 2 and x[0] == x[-1]:
- # counter += 1
- # return counter
- #
- # sample_list = ['abc', 'xyz', 'aba', '1221']
- # print(count_specific_str(sample_list))
- # # L5 (6)
- #
- # lst = [(2, 5), (1, 2), (4, 4), (2, 3), (2, 1)]
- #
- # for x in lst:
- #
- #
- # print(lst)
- # L6 (7) nie uzywac seta
- #### new_list = [x for n,x in enumerate(my_list) if x not in my_list[:n]]
- #### print(new_list)
- # def remove_duplicates(list):
- # new_list = []
- # for i,x in enumerate(list):
- # if x not in list[i+1:]:
- # new_list.append(x)
- # return new_list
- #
- # my_list = ['aaa', 'asd', 'aaa', 'qwe']
- # print(remove_duplicates(my_list))
- # L7 (10)
- # def find_words(list, n):
- # new_list = []
- # for x in list:
- # if len(x) > n:
- # new_list.append(x)
- # return new_list
- #
- # my_list = ['red', 'green', 'blue']
- # print(find_words(my_list, 3))
- # L8 (11)
- # list_1 = ['a', 'b', 'c', 'd']
- # list_2 = ['e', 'a', 'f', 'g']
- #
- # def common_element(list1, list2):
- # for x in list1:
- # if x in list2:
- # return True
- # break
- #
- # print(common_element(list_1, list_2))
- # L9 (12)
- # my_list = ['Red', 'Green', 'White', 'Black', 'Pink', 'Yellow']
- #
- # def remove_elements(list):
- # list = [x for (i,x) in enumerate(list) if i not in (0,4,5)]
- # return list
- #
- # print(remove_elements(my_list))
- # L10 (14)
- # my_list = [1,2,3,4,5,6]
- #
- # def remove_even_numbers(list):
- # for x in list:
- # if x % 2 == 0:
- # list.remove(x)
- # return list
- #
- # print(remove_even_numbers(my_list))
- # L11 (16)
- # def generate_square_numbers_to(n):
- # list = []
- # out_list = []
- # for x in range(1, n + 1):
- # list.append(x**2)
- # out_list.extend(list[:5])
- # out_list.extend(list[-5:])
- # return out_list
- #
- # print(generate_square_numbers_to(15))
- # L12 (18) nie uzywac itertools
- # lst = ['a', 'b', 'c']
- # def perm(a, k=0):
- # if k == len(a):
- # print(a)
- # else:
- # for i in range(k, len(a)):
- # a[k], a[i] = a[i] ,a[k]
- # perm(a, k+1)
- # a[k], a[i] = a[i], a[k]
- #
- # perm(lst)
- # L13 (19)
- # lst = ['a', 'b', 'c', 'e']
- # other_lst = ['d', 'b', 'c', 'w']
- #
- # def difference_between_lists(list1, list2):
- # result = []
- # for x in list1:
- # if x not in list2:
- # result.append(x)
- # return result
- #
- # print(difference_between_lists(lst, other_lst))
- # 20
- # nums = [5, 15, 35, 8 , 98]
- # for index, value in enumerate(nums):
- # print(index, value)
- # 21
- # lst = ['l', 'i', 's', 't']
- # s = ""
- # for x in lst:
- # s = s + x
- #
- # print(s)
- #
- # #other solution
- # ss = ''.join(lst)
- # print(ss)
- # 22
- # num = [10, 30, 4, -6]
- #
- # print(num.index(30))
- # 23
- # lst = [[2,4,3], [1,5,6], [9], [7,9,0]]
- # new_lst = []
- #
- # for x in lst:
- # for y in x:
- # new_lst.append(y)
- #
- # print(new_lst)
- # 27 sort
- # lst = [11, 23, 4, 6, 21]
- #
- # lst.sort()
- # print(lst[1])
- # 29 for in
- # lst = ['a', 'b', 'c', 'a']
- #
- # for i,x in enumerate(lst):
- # if x in lst[i+1:]:
- # lst.remove(x)
- # print(lst)
- # 31
- # lst = [1, 2, 3, 4, 5, 6, 7, 8]
- # counter = 0
- #
- # for x in lst:
- # if 3 <= x <= 6:
- # counter += 1
- #
- # print(counter)
- # 37
- # lst1 = ['a','b','c']
- # lst2 = ['e','a','g']
- #
- # for x in lst1:
- # if x in lst2:
- # print(x)
- # 42 min max range
- # lst = [4,6,9]
- # missing = []
- #
- # for x in range(min(lst), max(lst)):
- # if x not in lst:
- # missing.append(x)
- #
- # print(missing)
- '''to be done'''
- # 44
- #lst = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
- # 46
- # lst = [21, 11, 2, 55, 9, 10, 72, 18, 5]
- # new_lst = []
- #
- # for i,x in enumerate(lst, 1):
- # if i%2 == 1:
- # new_lst.append(x)
- #
- # print(new_lst)
- # 51
- # lst = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
- #
- # new_lst = [lst[i::3] for i in range(3)]
- #
- # print(new_lst)
- # 56
- # str1 = 'string'
- # lst = []
- #
- # for x in str1:
- # lst.append(x)
- #
- # print(lst)
- # 63
- # str1 = 'xxx'
- # lst = ['one', 'two', 'three', 'four']
- #
- # for i,x in enumerate(lst):
- # lst[i] = str1 + x
- #
- # print(lst)
- '''to be done'''
- # 64
- # lst1 = ['one', 'two', 'three']
- # lst2 = ['jeden', 'dwa', 'trzy']
- # str1 = ''
- # 69
- # lst = [[10, 20], [40], [30, 56, 25], [10, 20], [33], [40]]
- # new_lst = []
- #
- # for i,x in enumerate(lst, 1):
- # if x not in lst[i:]:
- # new_lst.append(x)
- #
- # print(new_lst)
- # z wykladu
- # l = ['a', 'aaa', 'aa']
- # r = [len(i) for i in l]
- # print(r)
- # L29
- # l1 = ['asd', 'ABc', 'qqq']
- # l2 = ['ASD', 'abc', 'qqq']
- #
- # def check_if_equal(l1, l2):
- # r1 = [x.lower() for x in l1]
- # r2 = [y.lower() for y in l2]
- # return r1 == r2
- #
- # print(check_if_equal(l1,l2))
- # L30
- # a)
- # A = ['agh', 'mtm', 'python']
- # B = ['python', 'rrrr', 'ddddd']
- #
- # def change_if_occurs(A, B):
- # C = []
- # for x in (A):
- # if x in B:
- # C.append("...")
- # else:
- # C.append(x)
- # return C
- #
- # print(change_if_occurs(A, B))
- # def change_if_occurs(A, B):
- # return [x if x not in B else '...' for x in A]
- #
- # print(change_if_occurs(A,B))
- # b)
- # A = ['agh', 'mtm', 'python']
- # B = ['python', 'rrrr', 'ddddd']
- #
- # def change_if_occurs(A, B):
- # return [x if x not in B else len(x)*'.' for x in A]
- #
- # print(change_if_occurs(A,B))
- # c)
- # A = ['agh', 'mtm', '_python_']
- # B = ['python', 'rrrr', 'ddddd']
- #
- # def change_if_occurs(A, B):
- # C = []
- # for x in A:
- # if x.startswith('_'):
- # x = x[1:]
- # if x.endswith('_'):
- # x = x[:-1]
- # if x in B:
- # C.append("...")
- # else:
- # C.append(x)
- # return C
- #
- # print(change_if_occurs(A,B))
- # d)
- #
- # A = ['agh', 'mtm', 'python']
- # B = ['python', 'rrrr', 'ddddd']
- #
- # def change_if_occurs(A, B):
- # return [x for x in A if x not in B]
- #
- # print(change_if_occurs(A,B))
- # L31
- # A = ['kot', 'pies', 'kon']
- # B = ['pies:dog', 'kot:cat']
- #
- # def change_strings(A, B):
- # C = [x.split(':') for x in B]
- # D = [val for sublist in C for val in sublist]
- # return [D[D.index(a)+1] if a in D else '?' for a in A]
- #
- # print(change_strings(A, B))
- # L32
- # a)
- # A = ['kilogram', 'mouse', 'tree']
- #
- # def add_category(A):
- # animal = ['dog', 'cat', 'mouse']
- # plant = ['tree', 'grass', 'flower']
- # unit = ['meter', 'kilogram', 'newton']
- # B = []
- # for x in A:
- # if x in animal:
- # x = x + ':animal'
- # B.append(x)
- # if x in plant:
- # x = x + ':plant'
- # B.append(x)
- # if x in unit:
- # x = x + ':unit'
- # B.append(x)
- # return B
- #
- # print(add_category(A))
- # b) to be done
- # L33
- # A = ['pies','kot','kot','zaba','kon','kon','kon','panda']
- #
- # def compress_words(A):
- # B = [A.count(x) for x in A]
- # C = list(zip(A, B))
- # D = []
- # for i,x in enumerate(C):
- # if x not in C[i+1:]:
- # D.append(x)
- # return D
- #
- # print(compress_words(A))
- # L34
- # string = 'Liczba 7 dzielona przez 2 daje liczbę 3.5 a 1 przez 8 daje liczbę 0.128'
- #
- # def bold_numbers(string):
- # pre = '<b>'
- # past = '</b>'
- # new_string = ''
- # for x in string.split():
- # if not x.isalpha():
- # x = f'{pre}{x}{past}'
- # new_string = new_string + x + ' '
- # else:
- # new_string = new_string + x + ' '
- # return new_string.rstrip()
- #
- # print(bold_numbers(string))
- # L35
- # s_in = 'ala 1.23456 ma 12.3456 kota 123.456'
- #
- # s_in_l = s_in.split()
- #
- # s_nbrs_l = [s for s in s_in_l if s[0].isnumeric()]
- #
- # min_prec = min([len(s.split('.')[-1]) for s in s_nbrs_l])
- #
- # s_nbrs_l1 = filter(lambda s: s[0].isnumeric(), s_in_l)
- # import re
- #
- # s = 'asas 10 103df 237 34.5 dsds'
- #
- # l = re.findall('\s+(\d+)\s+', s)
- #
- # print(l)
- # L36
- ####### DICTIONARIES #######
- # D1
- # d = {1: 2, 3: 4, 4: 3, 2: 1, 0: 0}
- #
- # import operator
- # def sort_by_values(d):
- # return sorted(d.items(), key=operator.itemgetter(1))
- #
- # print(sort_by_values(d))
- # D2
- # dic1={1:10, 2:20}
- # dic2={3:30, 4:40}
- #
- # def concatenate_dicts(d1, d2):
- # dic3 = {}
- # for d in d1, d2:
- # dic3.update(d)
- # return dic3
- #
- # print(concatenate_dicts(dic1,dic2))
- # D3
- # d1 = {'a': 1, 'b': 2}
- # key = 'a'
- #
- # def if_key_in_dict(dict, key):
- # if key in dict.keys():
- # return True
- # else:
- # return False
- #
- # print(if_key_in_dict(d1, key))
- # D4
- # d1 = {'dog':'animal', 'flower':'plant', 'ford':'car'}
- #
- # def dict_to_list(dict):
- # lst1 = []
- # for k, v in dict.items():
- # x = k + ':' + v
- # lst1.append(x)
- # return lst1
- #
- # print(dict_to_list(d1))
- # D5
- #
- # def generate_dict(N):
- # d = dict()
- # for x in range(1, N+1):
- # d[x] = x*x
- # return d
- #
- # print(generate_dict(5))
- # D6
- # def sum_values_in_dict(dict):
- # sum = 0
- # for x in dict.values():
- # sum += x
- # return sum
- # def sum_values_in_dict(dict):
- # return sum(dict.values())
- #
- # d1 = {'data1':100,'data2':-54,'data3':247}
- #
- # print(sum_values_in_dict(d1))
- # D7
- # def multiply_values_in_dict(dict):
- # result = 1
- # for x in dict.values():
- # result *= x
- # return result
- #
- # d1 = {'data1':2,'data2':3,'data3':4}
- #
- # print(multiply_values_in_dict(d1))
- # D8
- # myDict = {'a':1,'b':2,'c':3,'d':4}
- #
- # def remove_key_from_dict(key, dict):
- # if key in dict:
- # del dict[key]
- # return dict
- #
- # print(remove_key_from_dict('a', myDict))
- # D9
- # keys = ['red', 'green', 'blue']
- # values = ['#FF0000','#008000', '#0000FF']
- #
- # def map_list_into_dict(keys, values):
- # return dict(zip(keys, values))
- #
- # print(map_list_into_dict(keys, values))
- # D10
- # color_dict = {'red':'#FF0000',
- # 'green':'#008000',
- # 'black':'#000000',
- # 'white':'#FFFFFF'}
- #
- # def sort_dict_by_key(dict):
- # result = []
- # for key in sorted(dict):
- # result.append("%s: %s" % (key, dict[key]))
- # return result
- #
- # print(sort_dict_by_key(color_dict))
- # D11
- # my_dict = {'x':500, 'y':5874, 'z': 560}
- #
- # def return_key_with_max_value(dict):
- # return max(dict.keys(), key=(lambda k: dict[k]))
- #
- # print(return_key_with_max_value(my_dict))
- # D12
- # student_data = {'id1':
- # {'name': ['Sara'],
- # 'class': ['V'],
- # 'subject_integration': ['english, math, science']
- # },
- # 'id2':
- # {'name': ['David'],
- # 'class': ['V'],
- # 'subject_integration': ['english, math, science']
- # },
- # 'id3':
- # {'name': ['Sara'],
- # 'class': ['V'],
- # 'subject_integration': ['english, math, science']
- # },
- # 'id4':
- # {'name': ['Surya'],
- # 'class': ['V'],
- # 'subject_integration': ['english, math, science']
- # },
- # }
- #
- # def remove_duplicates_from_dict(dict):
- # result = {}
- # for key,value in dict.items():
- # if value not in result.values():
- # result[key] = value
- # return result
- #
- # print(remove_duplicates_from_dict(student_data))
- # D13
- # d1 = {'a': 100, 'b': 200, 'c':300}
- # d2 = {'a': 300, 'b': 200, 'd':400}
- #
- # def join_two_dicts(dict1, dict2):
- # d = {}
- # for x in dict1.keys():
- # if x in dict2.keys():
- # d.update({x:dict1[x] + dict2[x]})
- # else:
- # d.update({x:dict1[x]})
- # for y in dict2.keys():
- # if y not in dict1.keys():
- # d.update({y:dict2[y]})
- # return d
- #
- # print(join_two_dicts(d1, d2))
- # D14
- # str1 = 'kakao'
- #
- # def count_letters(str1):
- # d = {}
- # lst1 = list(str1)
- # for x in lst1:
- # cnt = 0
- # for y in str1:
- # if x == y:
- # cnt += 1
- # d.update({x:cnt})
- # return d
- #
- # print(count_letters(str1))
- # D15
- # def length_of_words_in_list(lst1):
- # d = {}
- # for x in lst1:
- # d.update({x:len(x)})
- # return d
- #
- # lst1 = ['pies', 'kot', 'kaczka']
- #
- # print(length_of_words_in_list(lst1))
- # D16
- # lst1 = ['pies', 'kot', 'ryba']
- # dict1 = {'pies':'dog', 'kot':'cat', 'ryba':'fish'}
- #
- # def change_words(lst1, dict1):
- # lst2 = []
- # for x in lst1:
- # if x in dict1.keys():
- # lst2.append(dict1[x])
- # return lst2
- #
- # print(change_words(lst1,dict1))
- # D17
- # ld = [{'name':'Zawisza', 'age':35, 'heigth': 150, 'married': True},
- # {'name':'Malińska','age':25, 'heigth': 170, 'married': True},
- # {'name':'Adamski', 'age':15, 'heigth': 160, 'married': False}]
- # a)
- # def find_the_oldest(ld):
- # sorted_list = sorted(ld, key = lambda i: i['age'])
- # return sorted_list[-1]['name']
- #
- # print(find_the_oldest(ld))
- # b)
- # def higher_than_150(ld):
- # ld1 = []
- # for x in ld:
- # if x['heigth'] > 150:
- # ld1.append(x)
- # return ld1
- #
- # print(higher_than_150(ld))
- # I1
- # a)
- # str1 = '01011001'
- #
- # def count_slopes(str1):
- # cnt = 0
- # for i,x in enumerate(str1[:-1]):
- # if not x == str1[i+1]:
- # cnt += 1
- # return cnt
- #
- # print(count_slopes(str1))
- # b)
- # str1 = '00111000100001'
- #
- # def show_slopes(str1):
- # str2 = ''
- # for i,x in enumerate(str1[:-1]):
- # if x == str1[i+1]:
- # str2 += '-'
- # else:
- # str2 += '*'
- # return str2
- #
- # print(show_slopes(str1))
- # c)
- # str1 = '001110100001'
- #
- # def show_rising_slopes(str1):
- # str2 = ''
- # for i,x in enumerate(str1):
- # if x == '1' and str1[i-1] == '0':
- # str2 += 'r'
- # else:
- # str2 += '-'
- # return str2
- #
- # print(show_rising_slopes(str1))
- # d)
- # str1 = '0011101000011010'
- #
- # def show_rising_slopes_and_max_period(str1):
- # str2 = ''
- # for i,x in enumerate(str1):
- # if x == '1' and str1[i-1] == '0':
- # str2 += 'r'
- # else:
- # str2 += '-'
- # lst1 = str2.split('r')
- # lst1.sort()
- # str2 = str2.replace(lst1[-1] + 'r', lst1[-1] + 'x')
- # return str2
- #
- # print(show_rising_slopes_and_max_period(str1))
- # I2
- # a = '001101010'
- # b = '101001100'
- #
- # def and_gate(a, b):
- # c = ''
- # for i,x in enumerate(a):
- # if x == '1' and b[i] == '1':
- # c += '1'
- # else:
- # c += '0'
- # return c
- #
- # print(and_gate(a,b))
- # I3
- # sda = '1100 0011'
- # scl = '1111 1111'
- #
- # def detect_start_and_stop(sda, scl):
- # out = ''
- # for i,x in enumerate(sda):
- # if x == '0' and scl[i] == '1' and sda[i-1] == '1' and scl[i-1] == '1':
- # out += 's'
- # elif x == '1' and scl[i] == '1' and sda[i-1] == '0' and scl[i-1] == '1':
- # out += 't'
- # elif x == ' ':
- # out += ' '
- # else:
- # out += '-'
- # return out
- #
- # print(detect_start_and_stop(sda, scl))
- # I4
- # a)
- # zd1 = 'ala ma kota. niebo jest niebieskie. dzisiaj jest piatek.'
- #
- # def capitalize_first_words(zd):
- # l1 = zd.split('. ')
- # l2 = []
- # out = ''
- # for x in l1:
- # l2.append(x.capitalize())
- # out = '. '.join(l2)
- # return out
- #
- #
- # print(capitalize_first_words(zd1))
- # b)
- # zd = 'Jakies zdanie, tu jest ok. Tu juz ,jest zle,tu tez. Tu jest, za duzo.'
- #
- # def put_correct_number_of_whitespaces(zd):
- # l1 = zd.split(',')
- # l2 = []
- # for x in l1:
- # x = x.strip()
- # l2.append(x)
- # out = ', '.join(l2)
- # return out
- #
- # print(put_correct_number_of_whitespaces(zd))
- # I5
- # I6
- # import os
- #
- # def remove_empty_lines(zd):
- # return os.linesep.join([s for s in zd.splitlines() if s])
- #
- #
- # zd = '''multi line string
- #
- #
- # jakis tak blabla'''
- #
- # print(remove_empty_lines(zd))
- # I7
- # a)
- # zd = '''python learning
- # some text
- # line with err'''
- #
- # def add_when_error(zd):
- # l1 = zd.split('\n')
- # out = ''''''
- # for x in l1:
- # if 'err' in x:
- # x = '*' + x
- # out = out + x + '\n'
- # else:
- # out = out + x + '\n'
- # return out
- #
- # print(add_when_error(zd))
- # b)
- # zd = '''blablaabla
- # asd error qwe
- # smssmmss
- # okok error qqq'''
- #
- # def find_error(zd):
- # zd1 = zd.lower()
- # l1 = zd1.split('\n')
- # out = ''
- # for x in l1:
- # if ' error ' in x:
- # x = '*' + x
- # out = out + x + '\n'
- # else:
- # out = out + x + '\n'
- # return out
- #
- # print(find_error(zd))
- # c)
- # I8
- # import re
- #
- # def trim_whitespaces(zd):
- # return re.sub(' +', ' ', zd)
- #
- # whitespaces = " abcd ef gh ijkl "
- # tabs = " abcde fgh ijkl"
- #
- # print(trim_whitespaces(tabs))
- # D17 a
- # l1 = [{'name':'Zawisza', 'age':35, 'heigth': 150, 'married': True},
- # {'name':'Malińska','age':25, 'heigth': 170, 'married': True},
- # {'name':'Adamski', 'age':15, 'heigth': 160, 'married': False}]
- #
- # def find_oldest(l1):
- # l2 = sorted(l1, key=lambda i: i['age'])
- # return l2[-1]['name']
- #
- # print(find_oldest(l1))
- # D12
- # dic = {'a': 1, 'b': 2, 'c': 3, 'd': 1, 'e': 2}
- #
- # def remove_duplicates(dic):
- # out = {}
- # for k,v in dic.items():
- # if v not in out.values():
- # out[k] = v
- # return out
- #
- # print(remove_duplicates(dic))
- # I1d
- # inp = '0011101000011010'
- #
- # def rising_edge(inp):
- # out = ''
- # for i,x in enumerate(inp):
- # if x == '1' and inp[i-1] == '0':
- # out += 'r'
- # else:
- # out += '-'
- # out2 = out.split('r')
- # out2.sort()
- # out = out.replace(out2[-1] + 'r', out2[-1] + 'x')
- # return out
- #
- # print(rising_edge(inp))
- # L21
- # l1 = ['ab', 'tg', 'pl', 'af']
- # l2 = ['qw', 'pl', 'dd', 'ab']
- #
- # def find_common(l1, l2):
- # out = []
- # for x in l1:
- # if x in l2:
- # out.append(x)
- # return out
- #
- # print(find_common(l1, l2))
- # D17b
- # dic = [{'name':'Zawisza', 'age':35, 'heigth': 150, 'married': True},
- # {'name':'Malińska','age':25, 'heigth': 170, 'married': True},
- # {'name':'Adamski', 'age':15, 'heigth': 160, 'married': False}]
- # def find_taller_than_150(dic):
- # out = []
- # for x in dic:
- # if x.get('heigth') > 150:
- # out.append(x.get('name'))
- # return out
- #
- # print(find_taller_than_150(dic))
- # def find_the_oldest(dic):
- # out = ''
- # age_list = []
- # for x in dic:
- # age_list.append(x.get('age'))
- # age_list.sort()
- # for x in dic:
- # if x.get('age') == age_list[-1]:
- # out = x.get('name')
- # return out
- #
- # print(find_the_oldest(dic))
- # I2
- # a = '001101010'
- # b = '101001100'
- #
- # def and_gate(a, b):
- # c = ''
- # for i,x in enumerate(a):
- # if x == '1' and b[i] == '1':
- # c += '1'
- # else:
- # c += '0'
- # return c
- #
- # print(and_gate(a,b))
- # L31
- # A = ('kot','pies','koń')
- # B = ('pies:dog','kot:cat')
- #
- # def replace_word(A,B):
- # C = []
- # out = []
- # for x in B:
- # C.extend(x.split(':'))
- # for x in A:
- # if x in C:
- # out.append(C[C.index(x)+1])
- # else:
- # out.append('?')
- # return out
- #
- # print(replace_word(A,B))
- # D10
- # dic = {3:'trzeci', 2:'drugi', 1:'pierwszy', 4:'czwarty'}
- #
- # def sort_by_key(dic):
- # l1 = []
- # out = {}
- # for x in dic.keys():
- # l1.append(x)
- # l1.sort()
- # for x in l1:
- # out.update({x:dic[x]})
- # return out
- #
- # print(sort_by_key(dic))
- # I1e
- # --r---r----r
- # inp = '001110100001'
- #
- # def period_counter(inp):
- # out = ''
- # for i,x in enumerate(inp):
- # if x == '1' and inp[i-1] == '0':
- # out += 'r'
- # else:
- # out += '-'
- # l1 = []
- # for i,x in enumerate(out):
- # if x == 'r':
- # l1.append(i)
- # l2 = []
- # for i,x in enumerate(l1,1):
- # if i < len(l1):
- # l2.append(l1[i]-l1[i-1])
- # return sum(l2) / len(l2)
- #
- # print(period_counter(inp))
- # L34
- # inp = 'Liczba 7 dzielona przez 2 daje liczbę 3.5 a 1 przez 8 daje liczbę 0.128'
- #
- # def bold_number(inp):
- # pre = '<b>'
- # past = '</b>'
- # out = ''
- # for x in inp.split():
- # if not x.isalpha():
- # out += pre + x + past + ' '
- # else:
- # out += x + ' '
- # out = out.rstrip()
- # return out
- #
- # print(bold_number(inp))
- # D14
- # str1 = 'kakao'
- #
- # def count_letters(inp):
- # dic = {}
- # for x in inp:
- # cnt = 0
- # for y in inp:
- # if x == y:
- # cnt += 1
- # dic.update({x:cnt})
- # return dic
- #
- # print(count_letters(str1))
- # I5
- # str1 = '''jakis tam se string
- # na wiele
- # linijek
- # XDD'''
- #
- # def text_to_right(inp):
- # arr = inp.split('\n')
- # lenghts = []
- # for x in arr:
- # lenghts.append(len(x))
- # newarr = []
- # for x in arr:
- # x = ' '*(max(lenghts)-len(x)) + x
- # newarr.append(x)
- # out = ''
- # for x in newarr:
- # out += x + '\n'
- # return out.rstrip()
- #
- # print(text_to_right(str1))
- # L33
- # inp = ('pies','kot','kot','zaba','kon','kon','kon','panda')
- #
- # def count_animals(inp):
- # ar1 = []
- # for x in inp:
- # ar1.append(inp.count(x))
- # ar2 = list(zip(inp, ar1))
- # ar3 = []
- # for i,x in enumerate(ar2):
- # if x not in ar2[i+1:]:
- # ar3.append(x)
- # return ar3
- #
- #
- # print(count_animals(inp))
- # L20
- # lst = [10,20,30,40,50,60,70,80,90]
- #
- # def count_numbers_in_range(lst, min, max):
- # cnt = 0
- # for x in lst:
- # if min <= x <= max:
- # cnt += 1
- # return cnt
- #
- # print(count_numbers_in_range(lst, 30, 60))
- # L26
- # xd = 'XD'
- # lst = ['jeden', 'dwa', 'trzy']
- #
- # def put_before_string(lst, str1):
- # out = []
- # for x in lst:
- # x = str1 + x
- # out.append(x)
- # return out
- #
- # print(put_before_string(lst, xd))
- # D13
- # dic1 = {'one':2, 'nnn':1, 'two':3}
- # dic2 = {'asd':1, 'two':2, 'one':3}
- #
- # def add_dics(dic1, dic2):
- # out = {}
- # for x in dic1.keys():
- # if x in dic2.keys():
- # out.update({x:dic1[x]+dic2[x]})
- # else:
- # out.update({x:dic1[x]})
- # for y in dic2.keys():
- # if y not in dic1.keys():
- # out.update({y:dic2[y]})
- # return out
- #
- # print(add_dics(dic1, dic2))
- # I7c
- # str1 = ''' jskadjis sadsad
- # askdoaskdosakd
- # sakokasd 3 asodkas
- # asd 213 sad d'''
- #
- # def I7c(str1):
- # l1 = str1.splitlines()
- # for i,x in enumerate(l1):
- # wrd = x.split(" ")
- # for y in wrd:
- # try:
- # float(y)
- # l1[i] = "*" + x
- # except ValueError:
- # pass
- # return '\n'.join(l1)
- #
- # print(I7c(str1))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement