Category : coding-style

Q:- Create a function based on the input and output. Look at the examples, there is a pattern.(Please check the link as I am unable to post examples here.) Example: Page of the question along with required output. My code def secret(a): b=a[:-2] a_list=list(a) last_number=int(a_list[-1]) Final_recurr=last_number+last_number d="{} ".format(b)*Final_recurr j=d.split() for i,k in enumerate(j): if int(i)%2!=0: ..

Read more

i have 3 character type columns in my table has time format values i.e while processing (in python 3.7) to in if condition i am using following statement; t1 = ’09:12′ t2 = ’09:10′ t3 = ’20:00′ if datetime.strptime(t1, ‘%H:%M’) > datetime.strptime(t2, ‘%H:%M’): print((datetime.strptime(t1, ‘%H:%M’) – datetime.strptime(t2, ‘%H:%M’))) # above prints 00:02 but i need ..

Read more

I want styling output log, but im have small problem with color this is what i do and my python code is def xprint_info(self, info, bold=False): jam = datetime.datetime.fromtimestamp(time.time()).strftime(‘%H:%M:%S’) jam = colored(jam, ‘cyan’) if bold: header = colored(‘INFO’, ‘green’,attrs=[‘bold’]) info = colored(info, ‘white’, attrs=[‘bold’]) else: header = colored(‘INFO’, ‘green’) info = colored(info, ‘white’) text = ..

Read more

grid = [[‘.’, ‘.’, ‘.’, ‘.’, ‘.’, ‘.’], [‘.’, ‘O’, ‘O’, ‘.’, ‘.’, ‘.’], [‘O’, ‘O’, ‘O’, ‘O’, ‘.’, ‘.’], [‘O’, ‘O’, ‘O’, ‘O’, ‘O’, ‘.’], [‘.’, ‘O’, ‘O’, ‘O’, ‘O’, ‘O’], [‘O’, ‘O’, ‘O’, ‘O’, ‘O’, ‘.’], [‘O’, ‘O’, ‘O’, ‘O’, ‘.’, ‘.’], [‘.’, ‘O’, ‘O’, ‘.’, ‘.’, ‘.’], [‘.’, ‘.’, ‘.’, ‘.’, ‘.’, ..

Read more

I want to convert this into a more readable for other programmers in the team, but I am not sure how properly refactor this function that merges two dict, and remove duplicates based on value def mergeDict(json1, json2): cveids = set([n[‘id’] for n in json1]).union(set([n[‘id’] for n in json2])) jf1={s[‘id’]:s[‘url’] for s in json1} jf2={s[‘id’]:s[‘url’] ..

Read more