Best Python code snippet using localstack_python
groups.py
Source:groups.py
1VALUES = [0, 25, 33, 50, 75, 100]2PROGRAMS = {3 'sd': ('SD', 'Software Development', '#FF0000'),4 'ai': ('AI', 'Artificial Intelligence', '#0000FF'),5 'csc': ('CSC', 'Cybersecurity & Cloud', '#00FF00'),6 'ti': ('TI', 'Technische Informatica', '#FFFF00'),7 'bim': ('BIM', 'Business IT Management', '#00FFFF')}8PROGRAM_NAMES = [p[0] for p in PROGRAMS.values()]9def is_valid_groupchoice(choices):10 names = [choice[0] for choice in choices]11 values = [choice[1] for choice in choices]12 all_exist = True13 for name in names:14 all_exist = all_exist and name in PROGRAM_NAMES15 for value in values:16 all_exist = all_exist and value in VALUES17 distinct = len(set(names)) == len(names)18 sums_to_hundred = sum(values) in [100, 99] # rounding stuff with the 33%ers19 return all_exist and distinct and sums_to_hundred20def initial_groups():21 groups = {}22 for i in range(6):23 groups[f'Team {i + 1}'] = []24 return groups25def remove_student_choice(model, to_remove):26 for name, members in model.items():27 for student in members:28 if student['name'] == to_remove:29 members.remove(student)30def add_student_choice(model, team, student, choices):31 if not is_valid_groupchoice(choices):32 raise Exception('Invalid choices')33 remove_student_choice(model, student)34 model[team].append({'name': student, 'choices': choices})35MIN_TEAM_SIZE = 436def get_team_distribution(team):37 team = list(team) # create a copy so we don't edit the input list38 if len(team) < MIN_TEAM_SIZE:39 # pad the list with 'empties', so it's clear there is still stuff missings40 for i in range(len(team), MIN_TEAM_SIZE):41 team.append({'name': 'NONE', 'choices': [('NONE', 100)]})42 values = {}43 total = 044 for student in team:45 for program, value in student['choices']:46 if program not in values.keys():47 values[program] = value48 else:49 values[program] = values[program] + value50 total += value51 # normalise to 100%52 factor = 100 / total53 for key, value in values.items():54 values[key] = factor * value55 return values56def dummy_data(model):57 add_student_choice(model, 'Team 1', 'Arie de Groot', [('SD', 100)])58 add_student_choice(model, 'Team 1', 'Bruno Verkade', [('TI', 50), ('CSC', 50)])59 add_student_choice(model, 'Team 1', 'Chris Lemontagne', [('AI', 33), ('BIM', 33), ('CSC', 33)])60 add_student_choice(model, 'Team 1', 'Drummond Lee', [('SD', 100)])61 add_student_choice(model, 'Team 2', 'Effi De Geus', [('SD', 100)])...
exercise_01.py
Source:exercise_01.py
1# def find_words(words, chars):2# chars_dict = {}3# for char in chars:4# if char not in chars_dict:5# chars_dict[char] = 16# else:7# chars_dict[char] += 18# possible_words = []9# for word in words:10# word_dict = {}11# for char in word:12# if char not in word_dict:13# word_dict[char] = 114# else:15# word_dict[char] += 116# all_exist = True17# for key, value in word_dict.items():18# if key not in chars_dict:19# all_exist = False20# break21# else:22# if chars_dict[key] < value:23# all_exist = False24# if all_exist:25# possible_words.append(word_dict)26# count = 027# for word in possible_words:28# for key, value in word.items():29# count += value30# return count31def find_words(words, chars):32 chars_dict = {}33 for char in chars:34 if char not in chars_dict:35 chars_dict[char] = 136 else:37 chars_dict[char] += 138 count = 039 for word in words:40 chars_dict_copy = chars_dict.copy()41 all_exist = True42 for char in word:43 if char not in chars_dict:44 all_exist = False45 break46 if chars_dict_copy[char] < 1:47 all_exist = False48 break49 chars_dict_copy[char] -= 150 if all_exist:51 count += len(word)...
main.py
Source:main.py
1from functools import reduce2all_answers = open('input.txt', 'r').read()3print(all_answers)4groups = all_answers.split('\n\n')5# print(groups)6# current_group_yesses = []7# groups = []8# for l in all_answers:9# if l == '':10# groups.append(current_group_yesses)11# current_group_yesses = []12# continue13# current_group_yesses.append(l)14# groups.append(current_group_yesses)15counts = []16for g in groups:17 all_exist = set()18 for c in g[0]:19 all_exist.add(c)20 for i in range(1, len(g)):21 all_exist = all_exist.intersection(set(g[i]))22 counts.append(len(all_exist))...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!