Best Python code snippet using localstack_python
Builder_Director.py
Source:Builder_Director.py
...101 def __init__(self):102 self.parts = []103 def add(self, part):104 self.parts.append(part)105 def list_parts(self):106 print(f'Produced parts:')107 for part in range(len(self.parts)):108 print(self.parts[part])109 print('\n')110def clear_cmd():111 if platform.system() == 'Linux':112 os.system('clear')113 elif platform.system() == 'Windows':114 os.system('cls')115# Menu items choosing function116def select_menu_item(itemlist: list):117 item = int(-1)118 while item not in itemlist:119 try:120 item = int(input('Enter your choice: '))121 if item < min(itemlist) or item > max(itemlist):122 print(f'\nOperation \"{item}\" is not available\n')123 except ValueError:124 print('\nInput value error\nNot an integer\n\nPlease repeat the input\n\n')125 return item126if __name__ == "__main__":127 clear_cmd()128 # House initialization for custom house (made by group of builders)129 house = House()130 # Builders initialization131 builder_stone = StoneBuilder()132 builder_wood = WoodenBuilder()133 builder_jelly = JellyBuilder()134 # Director initialization135 director = Director()136 print('##############################')137 print('Producing with Director\n')138 # Building full-wooden house using Director139 director.builder = builder_wood140 director.build_full_house()141 builder_wood.house.list_parts()142 # All kind of available producing configurations with Director143 # (Each director's function creates new object wih another configuration)144 # Walls and Door145 director.builder = builder_jelly146 director.build_walls_and_door()147 builder_jelly.house.list_parts()148 # Full Jelly House149 director.build_full_house()150 builder_jelly.house.list_parts()151 # Windows and Roof152 director.build_windows_and_roof()153 builder_jelly.house.list_parts()154 # Stone windows and Roof155 director.builder = builder_stone156 director.build_windows_and_roof()157 builder_stone.house.list_parts()158 print('##############################n\n\n')159 # Custom configuration160 print('##############################')161 print('Client\'s custom configuration\n')162 builder_jelly.make_walls()163 builder_wood.make_door()164 builder_wood.make_roof()165 builder_stone.make_walls()166 # We can see what each of builders has done167 builder_jelly.house.list_parts()168 builder_wood.house.list_parts()169 builder_stone.house.list_parts()170 # or like this171 print('Client\'s custom configuration\n')172 builder_jelly.make_walls()173 builder_wood.make_door()174 builder_wood.make_roof()175 builder_stone.make_walls()176 house.parts = builder_jelly.house.parts + builder_wood.house.parts + builder_stone.house.parts177 house.list_parts()...
17-NumberToWords.py
Source:17-NumberToWords.py
1# 17. Number to Words2# Language: Python 33# Testcases: 6/64def num_to_word(a,ind_a,p):5 units = ['','One','Two','Three','Four','Five','Six','Seven','Eight','Nine']6 teens = ['Ten','Eleven','Twelve','Thirteen','Fourteen','Fifteen','Sixteen','Seventeen','Eighteen','Nineteen']7 tens = ['','Ten','Twenty','Thirty','Forty','Fifty','Sixty','Seventy','Eighty','Ninety']8 word = ""9 if(len(str(a))==1):10 if(a!=0):11 word = units[a]12 else:13 word = ""14 elif(len(str(a))==2):15 if(a==0):16 word = ""17 elif(a<20):18 word = teens[a-10]19 else:20 word = tens[int(str(a)[-2])]+" "+units[int(str(a)[-1])]21 elif(len(str(a))==3):22 if(a==0):23 word = ""24 elif(int(str(a)[-2:])<10):25 word = units[a//100]+" Hundred "+units[int(str(a)[-1])]26 elif(int(str(a)[-2:])<20):27 word = units[a//100]+" Hundred "+teens[int(str(a)[-1])]28 else:29 word = units[a//100]+" Hundred "+tens[int(str(a)[-2])]+" "+units[int(str(a)[-1])]30 if(p-ind_a==4 and a!=0):31 word+=" Billion "32 elif(p-ind_a==3 and a!=0):33 word+=" Million "34 elif(p-ind_a==2 and a!=0):35 word+=" Thousand "36 return word37T=int(input())38while(T!=0):39 N=int(input())40 list_parts = []41 if(len(str(N))%3!=0):42 parts=len(str(N))//3+143 else:44 parts=len(str(N))//345 if(parts==1):46 list_parts.append(int(str(N)))47 elif(parts==2):48 list_parts.append(int(str(N)[:-3]))49 list_parts.append(int(str(N)[-3:]))50 elif(parts==3):51 list_parts.append(int(str(N)[:-6]))52 list_parts.append(int(str(N)[-6:-3]))53 list_parts.append(int(str(N)[-3:]))54 elif(parts==4):55 list_parts.append(int(str(N)[:-9]))56 list_parts.append(int(str(N)[-9:-6]))57 list_parts.append(int(str(N)[-6:-3]))58 list_parts.append(int(str(N)[-3:]))59 word_string = ""60 count=061 for i in list_parts:62 word_string+=num_to_word(i,count,parts)63 count+=164 if(N==0):65 word_string+="Zero"66 elif(N==1000000000000):67 word_string+="One Thousand Billion"68 print(word_string.replace(' ',' '))...
extract_imagenet.py
Source:extract_imagenet.py
1import os2import pickle3import numpy as np4from skimage import io567path = '/media/annusha/BigPapa/Study/DL/ImageNet32/'8folder = 'train'9list_parts = [i for i in os.listdir(os.path.join(path, folder))10 if os.path.isfile(os.path.join(path, folder, i))]1112# list_parts = [list_parts[0]]1314out_path = '/media/annusha/BigPapa/Study/DL/ImageNet_images/'1516if os.path.isdir(out_path):17 pass18else:19 os.mkdir(out_path)2021counter = 022label_path = '/media/annusha/BigPapa/Study/DL/label_imagenet'2324for f in list_parts:25 file = os.path.join(path, folder, f)26 fo = open(file, 'rb')27 entry = pickle.load(fo)28 x = entry['data']29 y = entry['labels']30 mean_img = entry['mean']3132 fo.close()3334 x = x / np.float32(255)35 # mean_img = mean_img / np.float32(255)3637 y = [i - 1 for i in y]3839 # x -= mean_img40 image_size = 3241 image_size_2x = image_size * image_size42 x = np.dstack((x[:, :image_size_2x], x[:, image_size_2x:2 * image_size_2x], x[:, 2 * image_size_2x:]))43 x = x.reshape((x.shape[0], image_size, image_size, 3))44 print(x.shape)4546 for im, im_y in zip(x, y):47 io.imsave(os.path.join(out_path, '%d.jpeg'%counter), im)48 with open(label_path, '+a') as fl:49 fl.write(os.path.join(out_path, '%d.png %d\n'%(counter, im_y)))5051 counter += 15253 if counter % 1000 == 0:54 print('done %d\n'%counter)
...
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!!