Best Python code snippet using tempest_python
main.py
Source: main.py
...6import pandas as pd7from grow_decision_tree import grow_tree, plot, prune, predict8import matplotlib.pyplot as plt9import networkx as nx10def get_hash_dict(d_tree, hash_dict):11 if d_tree.branch_with_value is not None:12 hash_dict[d_tree.__hash__()] = {'value':d_tree.value,13 'col':d_tree.col_name,14 'children': [d_tree.branch_with_value.__hash__(), d_tree.branch_with_others.__hash__()],15 'size':d_tree.set_size16 }17 get_hash_dict(d_tree.branch_with_value, hash_dict)18 get_hash_dict(d_tree.branch_with_others, hash_dict)19def get_neighborhood_list(d_tree):20 # tworzymy pusty sÅownik, do którego bedziemy dopisywaÄ informacje o strukturze drzewa21 hash_dict = {}22 # d_tree to jest drzewo23 get_hash_dict(d_tree, hash_dict)24 # verticles to lista kluczy d_tree.__hash__(), czyli wierzchoÅki25 vertices = [k for k in hash_dict.keys()]26 # do wierzchoÅków dopisujemy wszystkie dzieci - również liÅcie (czyli dzieci które nie staÅy siÄ parentsami)27 # robimy to ponieważ w funkcji get_hash_dict (przez warunek if d_tree.branch_with_value is not None:) nie uwzglÄdniamy dzieci, które nie sÄ
parentsami (liÅcie)28 for v in hash_dict.values():29 vertices.extend(v['children'])30 # używamy set, czyli struktury danych która jest listÄ
bez powtórzeÅ. Skoro wzieliÅmy wszystkie dzieci, to mogÄ
31 # wsytÄpowaÄ powtórzenia, ponieważ niektóre dzieci sÄ
zarówno dzieÄmi jak i parentsami32 hashes = set(vertices)33 # tworzymy mapowanie k:i gdzie k jest kluczem a "i" intigerem34 hash_to_int = {k:i for i,k in enumerate(hashes)}35 neighborhood_list = {}36 for k,v in hash_dict.items():37 neighborhood_list[hash_to_int[k]]={'value': v['value'],...
status.py
Source: status.py
...38def hash_file(path: str) -> str:39 file_text = read_file(path)40 file_hash = hashlib.sha1(file_text.encode('utf-8')).hexdigest()41 return file_hash42def get_hash_dict(path: str) -> dict:43 44 files = list_files(path)45 hash_collection = {}46 for file in files:47 hash_collection[file] = hash_file(path + file)48 49 return hash_collection50def save_hash_dict(path: str) -> None:51 with open(path + '.geet/.hashdict.json', 'w') as writer:52 hash_dict = get_hash_dict(path)53 json.dump(hash_dict, writer)54 return None55def read_current_hash_dict(path: str) -> dict:56 with open(path + '.geet/.hashdict.json', 'r') as reader:57 file = reader.read()58 return json.loads(file)59def scan_for_new_files(path: str) -> list:60 previous_files = read_current_hash_dict(path).keys()61 current_files = get_hash_dict(path).keys()62 new_files = []63 for file in current_files:64 if file not in previous_files:65 new_files.append(file)66 return new_files67def scan_for_deleted_files(path: str) -> list:68 69 previous_files = read_current_hash_dict(path).keys()70 current_files = get_hash_dict(path).keys()71 deleted_files = []72 for file in previous_files:73 if file not in current_files:74 deleted_files.append(file)75 return deleted_files76def scan_for_modified_files(path: str) -> list:77 previous_hash_dict = read_current_hash_dict(path)78 current_hash_dict = get_hash_dict(path)79 previous_files = previous_hash_dict.keys()80 current_files = current_hash_dict.keys()81 modified_files = []82 for file in current_files:83 if file in previous_files:84 if previous_hash_dict[file] != current_hash_dict[file]:85 modified_files.append(file)86 return modified_files87 88# PATH = get_current_path()89# print(get_current_path())90# print(get_tree_files(PATH))91# print(list_files(PATH))92# print(read_file(PATH + 'main.py'))93# print(read_file_by_lines(PATH + 'main.py'))94# print(hash_file(PATH + 'main.py'))95# print(get_hash_dict(PATH))96# print(save_hash_dict(PATH))97# print(read_current_hash_dict(PATH))98# print("New files:", scan_for_new_files(PATH))99# print("Deleted files:", scan_for_deleted_files(PATH))...
ransom_note.py
Source: ransom_note.py
2# ransom_note.py3# https://www.hackerrank.com/challenges/ctci-ransom-note/4# Complete the checkMagazine function below.5def checkMagazine(magazine, note):6 hash_dict_note = get_hash_dict(note)7 hash_dict_magazine = get_hash_dict(magazine)8 for k,v in hash_dict_note.items():9 note_count = hash_dict_note.get(k)10 magazine_count = hash_dict_magazine.get(k)11 if (not magazine_count) or (magazine_count < note_count):12 return False13 return True14def get_hash_dict(input_list):15 counts = dict()16 for i in input_list:17 counts[i] = counts.get(i, 0) + 118 return(counts)19magazine = "apgo clm w lxkvg mwz elo bg elo lxkvg elo apgo apgo w elo bg".split()20note = "elo lxkvg bg mwz clm w".split()21# magazine = "give me one grand today night".split()22# note = "give one grand round today".split()...
Check out the latest blogs from LambdaTest on this topic:
These days, development teams depend heavily on feedback from automated tests to evaluate the quality of the system they are working on.
I think that probably most development teams describe themselves as being “agile” and probably most development teams have standups, and meetings called retrospectives.There is also a lot of discussion about “agile”, much written about “agile”, and there are many presentations about “agile”. A question that is often asked is what comes after “agile”? Many testers work in “agile” teams so this question matters to us.
I routinely come across test strategy documents when working with customers. They are lengthy—100 pages or more—and packed with monotonous text that is routinely reused from one project to another. Yawn once more— the test halt and resume circumstances, the defect management procedure, entrance and exit criteria, unnecessary generic risks, and in fact, one often-used model replicates the requirements of textbook testing, from stress to systems integration.
To understand the agile testing mindset, we first need to determine what makes a team “agile.” To me, an agile team continually focuses on becoming self-organized and cross-functional to be able to complete any challenge they may face during a project.
When working on web automation with Selenium, I encountered scenarios where I needed to refresh pages from time to time. When does this happen? One scenario is that I needed to refresh the page to check that the data I expected to see was still available even after refreshing. Another possibility is to clear form data without going through each input individually.
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!!