Package: ashfaquecodes
How to installpipinstallashfaquecodesDocumentationColor the printed outputs in terminal.fromashfaquecodes.ashfaquecodesimport(,blue_print_start,red_print_start,green_print_start,color_print_reset)importpprintpp=pprint.PrettyPrinter(indent=4)# blue_print_start()red_print_start()# green_print_start()pp.pprint("--------------------------")color_print_reset()Get a unique list if list of non-unique elements passed in this function.fromashfaquecodes.ashfaquecodesimportunique_list_=unique_list(non_unique_list)Get unique list of dictionaries if a list of duplicate dictionaries passed in this function.fromashfaquecodes.ashfaquecodesimportunique_list_of_dicts_=unique_list_of_dicts(non_unique_list_of_dicts)Get a list of non-empty dictionaries if a list of empty and non-empty dictionaries passed in this function.fromashfaquecodes.ashfaquecodesimportremove_empty_dicts_from_list_=remove_empty_dicts_from_list(list_with_empty_dicts)Get a sorted list of dictionaries returned according to your desired sorting key of the dictionary if a list of non-empty dictionaries passed in this function. Supports ascending and descending order.fromashfaquecodes.ashfaquecodesimportsort_list_of_dicts_=sort_list_of_dicts(unsorted_list=unsorted_lst,key='dict_key_name',desc=True)Get execution time of your code. Can also prints the execution time in terminal if an optional parameterprint_time = Trueis passed in the function.fromashfaquecodes.ashfaquecodesimport(get_execution_start_time,get_execution_end_time)execution_start_time=get_execution_start_time()total_execution_time_str=get_execution_end_time(execution_start_time,print_time=True)Custom Decorator to calculate execution time of a function which will be printed in the terminal during execution of that function.fromashfaquecodes.ashfaquecodesimporttimer@timerdefyour_function(request):passCustomcprint()function to print output in the terminal with different colors.fromashfaquecodes.ashfaquecodesimportcprintcprint('This is '+'a'+' test print statement',color='red')cprint('This is an error message',color='green')cprint("Python :%2d, Portal :%5.2f"%(1,05.333),color='yellow')cprint("Total students :%3d, Boys :%2d"%(240,120),color='blue')cprint("%7.3o"%(25),color='magenta')cprint("%10.3E"%(356.08977),color='cyan')cprint('I love "{}!"'.format('Python'),color='white')cprint(f"I love{'Python'}\"{'Language'}!\"",color='red')data=dict(fun="Python",adj="Portal")cprint("I love{fun}computer{adj}".format(**data),color='red')cstr="I love Python"# Printing the center aligned string with fillchrcprint("Center aligned string with fillchr: ",color='green')cprint(cstr.center(40,'#'),color='yellow')# cprinting the left aligned string with "-" paddingcprint("The left aligned string is : ",color='blue')cprint(cstr.ljust(40,'-'),color='magenta')# cprinting the right aligned string with "-" paddingcprint("The right aligned string is : ",color='cyan')cprint(cstr.rjust(40,'-'),color='white')Customcpprintfunction to pprint output in the terminal with different colors and different formats.fromashfaquecodes.ashfaquecodesimportcpprintsample_data={'key5':'value1','key2':'value2','key3':{'nested_key':'nested_value','nested_dict':{'deep_key':'deep_value'}},'key4':[1,2,3,4,5],'key1':[{'name':'John','age':30},{'name':'Alice','age':25},{'name':'Bob','age':35}]}cpprint(sample_data,indent=4,color='green',width=80,depth=2,compact=False,sort_dicts=True)# Available colors: ['red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white']LicenseGNU GPLv3