8

Welcome to CR community. Keep constant declarations at the top. Although you follow the PEP8 naming conventions throughout (almost) the whole code base, constant (or globals) are named as UPPER_SNAKE_CASE. So, the pizza_prices would become PIZZA_PRICES. Use triple-quoted strings in python for multiline content. Your print statements would look a lot ...


6

Your code is quite nice. Your use of functions seem quite reasonable. And your style is nice too. Good job! Calling print is expensive. To improve performance we can build the strings without using the for loop. For example to build \$n-(i + 1)\$ spaces we can use: >>> n = 12; i = 1 >>> " " * (n - (i + 1)) ' ' To build ...


5

There are a couple choices, but the best is to record the value's index on Card creation: self.order = value._member_names_.index(value.name) Then your comparison can use self.order directly: return self.order < other.order _member_names_ is a supported attribute and won't be going away.


4

Welcome to Code Review. Your code looks to be following some good practices from python's style guide (PEP-8). However, as a programmer, you can perhaps improve the structure/performance. No need to have separate variables for dataframes for each club. Group all the links together, and use a map for fetch everything. The reverse function defines an unused ...


4

You use three different names for the same thing. You ask for Height, then call it num, then call it n. I'd just call the variables height, both to be consistent and to be meaningful. At least in main and print_pyramid, as there it really means height. In print_spaces it's perhaps better to keep calling the parameter n, as that function doesn't need to know ...


3

You can define an __init__ method for an Enum. It gets passed the value of each enum member. Use it to define an order attribute for each enum member. For example, the Enum member Ace = "Ace" calls __init__ with value = "Ace", and CardValue.ACE.order will be set to '__23456789TJQKA'.index(value[0]), which is 14. Also, define __eq__ and ...


3

First improvement I see is mathematical: to check if a number n is prime, it's sufficient to verify that it's not divisible by any integer between 2 and math.ceil(math.sqrt(n)) (don't forget to import math at the top of your file). That's going to make your program more efficient. Another improvement would be to split the code that deals with getting the ...


2

You try all pairs and besides comparing the keys, you check whether their values are equal. It's faster to only try pairs whose values are equal, and you can do this by first categorizing by value. def filtered(mydict): items_for_value = {} for item in mydict.items(): items_for_value.setdefault(item[1], []).append(item) newdict = {} for key1, ...


2

One tip: use the argparse module. import argparse parser = argparse.ArgumentParser() parser.add_argument("--log_file", dest="log_file", type=str, required=True, help="Add some help text here") parser.add_argument("--input_file", dest="input_file", type=str, required=True, help="Add some help text ...


2

We should remove the file information from the loops. We should interact with the files and the output outside the loop. Note: Code changed to follow a standard Python style def generate_numbers(update, length): chunks = 1 while True: for u in range(1, 501): for g in range(1, 500): if chunks * (g + (u - 1) * 500) &...


2

Your code is quite easy to follow. So good job for that. There is still some room for improvement. Not loads of changes. Clear screen Python has certain functions to clear any text printed on the console. Check this page for all the information. if you are on windows, you can pip install os and then import os at the top of your program to use these ...


1

if resolve_hostname: host = reverse_dns_lookup(best_route, get_gateway_of(best_route), **sr_kwargs) if isinstance(host, str): _cell_print(f"{host} [{best_route}]") else: _cell_print(best_route) else: _cell_print(best_route) You are doing _cell_print and using best_route in each case, which is also the default value. ...


1

Unnecessary format strings Unless you intend to format a string right then and there, you don't need an f before it. Regex This can be reduced to one line using regex: import re l3 = [item for item in l1 if re.match(r"\w{3,5}[.]\d\s[=]\s\d{1,}", item)] Explanation \w{3,5} matches any word character (equal to [a-zA-Z0-9_]) {3,5} Quantifier — ...


1

O(n * d^2) solution The original code runs in O(n^2) time. This code runs in O(n d^2) where n is the length of mydict and d is the length of a key. The final code is at the bottom of the post. Here is how I got there: First, I had the same idea as @HeapOverflow, but then decided to try another approach. For any key, value in mydict, we can create all the ...


1

I can't test it at the moment, but I suspect that the culprit is output += chunk in a couple of places. This line potentially has O(n^2) complexity because of copying output to a new place in memory that has room to append chunk to it. It would be more efficient to append chunk to a list and then use b''.join() at the end to concatenate all the chunks. def ...


Only top voted, non community-wiki answers of a minimum length are eligible