Skip to main content
Commonmark migration
Source Link

Nice PEP8 compliant code, Phrancis. Good job! I only have two comments to make regarding that: you usually have to use triple-double quoted strings when it comes to docstrings. From the docs (PEP257):

For consistency, always use """triple double quotes""" around docstrings. Use r"""raw triple double quotes""" if you use any backslashes in your docstrings. For Unicode docstrings, use u"""Unicode triple-quoted strings""" .

More, you missed one newline between your imports and the first function. It's not such a big deal but I thought it's worth mentioning it.

In this line:

...
return file_.read().replace("\"", "").split(",")

You can use single quotes to get rid of the escape character \:

return file_.read().replace('"', '').split(',')

You can also omit the read file mode as that's the default mode when you read a file:

with open(file_path) as file_:
    ...

There's more than one place where you wrote:

something = list(string)

Instead of the situation where you sorted the list, you don't need list(string) because you can already iterate a string just fine.

###Use enumerate() more often.

Use enumerate() more often.

The enumerate() function adds a counter to an iterable. That said, you can rewrite your get_alpha_values() function like this:

def get_alpha_values() -> Dict:
    alpha_values = {}
    for index, letter in enumerate(string.ascii_uppercase, 1):
        alpha_values[letter] = index
    return alpha_values

Enumerate takes a second argument which lets you start from whatever position you want (in our case, that would be 1).

We can also make use of the get() method of the dicts and make your get_word_alpha_value() more straightforward:

def get_word_alpha_value(word: str, alpha_values: Dict) -> int:
    return sum([alpha_values.get(letter, 0) for letter in word])

The get method of a dict (like for example characters) works just like indexing the dict, except that, if the key is missing, instead of raising a KeyError it returns the default value (if you call .get with just one argument, the key, the default value is None)

Nice PEP8 compliant code, Phrancis. Good job! I only have two comments to make regarding that: you usually have to use triple-double quoted strings when it comes to docstrings. From the docs (PEP257):

For consistency, always use """triple double quotes""" around docstrings. Use r"""raw triple double quotes""" if you use any backslashes in your docstrings. For Unicode docstrings, use u"""Unicode triple-quoted strings""" .

More, you missed one newline between your imports and the first function. It's not such a big deal but I thought it's worth mentioning it.

In this line:

...
return file_.read().replace("\"", "").split(",")

You can use single quotes to get rid of the escape character \:

return file_.read().replace('"', '').split(',')

You can also omit the read file mode as that's the default mode when you read a file:

with open(file_path) as file_:
    ...

There's more than one place where you wrote:

something = list(string)

Instead of the situation where you sorted the list, you don't need list(string) because you can already iterate a string just fine.

###Use enumerate() more often.

The enumerate() function adds a counter to an iterable. That said, you can rewrite your get_alpha_values() function like this:

def get_alpha_values() -> Dict:
    alpha_values = {}
    for index, letter in enumerate(string.ascii_uppercase, 1):
        alpha_values[letter] = index
    return alpha_values

Enumerate takes a second argument which lets you start from whatever position you want (in our case, that would be 1).

We can also make use of the get() method of the dicts and make your get_word_alpha_value() more straightforward:

def get_word_alpha_value(word: str, alpha_values: Dict) -> int:
    return sum([alpha_values.get(letter, 0) for letter in word])

The get method of a dict (like for example characters) works just like indexing the dict, except that, if the key is missing, instead of raising a KeyError it returns the default value (if you call .get with just one argument, the key, the default value is None)

Nice PEP8 compliant code, Phrancis. Good job! I only have two comments to make regarding that: you usually have to use triple-double quoted strings when it comes to docstrings. From the docs (PEP257):

For consistency, always use """triple double quotes""" around docstrings. Use r"""raw triple double quotes""" if you use any backslashes in your docstrings. For Unicode docstrings, use u"""Unicode triple-quoted strings""" .

More, you missed one newline between your imports and the first function. It's not such a big deal but I thought it's worth mentioning it.

In this line:

...
return file_.read().replace("\"", "").split(",")

You can use single quotes to get rid of the escape character \:

return file_.read().replace('"', '').split(',')

You can also omit the read file mode as that's the default mode when you read a file:

with open(file_path) as file_:
    ...

There's more than one place where you wrote:

something = list(string)

Instead of the situation where you sorted the list, you don't need list(string) because you can already iterate a string just fine.

Use enumerate() more often.

The enumerate() function adds a counter to an iterable. That said, you can rewrite your get_alpha_values() function like this:

def get_alpha_values() -> Dict:
    alpha_values = {}
    for index, letter in enumerate(string.ascii_uppercase, 1):
        alpha_values[letter] = index
    return alpha_values

Enumerate takes a second argument which lets you start from whatever position you want (in our case, that would be 1).

We can also make use of the get() method of the dicts and make your get_word_alpha_value() more straightforward:

def get_word_alpha_value(word: str, alpha_values: Dict) -> int:
    return sum([alpha_values.get(letter, 0) for letter in word])

The get method of a dict (like for example characters) works just like indexing the dict, except that, if the key is missing, instead of raising a KeyError it returns the default value (if you call .get with just one argument, the key, the default value is None)

added 69 characters in body
Source Link
Grajdeanu Alex
  • 9.3k
  • 4
  • 32
  • 71

Nice PEP8 compliant code, Phrancis. Good job! I only have two comments to make regarding that: you usually have to use triple-double quoted strings when it comes to docstrings. From the docs (PEP257):

For consistency, always use """triple double quotes""" around docstrings. Use r"""raw triple double quotes""" if you use any backslashes in your docstrings. For Unicode docstrings, use u"""Unicode triple-quoted strings""" .

More, you missed one newline between your imports and the first function. It's not such a big deal but I thought it's worth mentioning it.

In this line:

...
return file_.read().replace("\"", "").split(",")

You can use single quotes to get rid of the escape character \:

return file_.read().replace('"', '').split(',')

You can also omit the read file mode as that's the default mode when you read a file:

with open(file_path) as file_:
    ...

There's more than one place where you wrote:

something = list(string)

Instead of the situation where you sorted the list, you don't need list(string) because you can already iterate a string just fine.

###Use enumerate() more often.

YouThe enumerate() function adds a counter to an iterable. That said, you can rewrite your get_alpha_values() function like this:

def get_alpha_values() -> Dict:
    alpha_values = {}
    for index, letter in enumerate(string.ascii_uppercase, 1):
        alpha_values[letter] = index
    return alpha_values

Enumerate takes a second argument which lets you start from whatever position you want (in our case, that would be 1).

We can also make use of the get() method of the dicts and make your get_word_alpha_value() more straightforward:

def get_word_alpha_value(word: str, alpha_values: Dict) -> int:
    return sum([alpha_values.get(letter, 0) for letter in word])

The get method of a dict (like for example characters) works just like indexing the dict, except that, if the key is missing, instead of raising a KeyError it returns the default value (if you call .get with just one argument, the key, the default value is None)

Nice PEP8 compliant code, Phrancis. Good job! I only have two comments to make regarding that: you usually have to use triple-double quoted strings when it comes to docstrings. From the docs (PEP257):

For consistency, always use """triple double quotes""" around docstrings. Use r"""raw triple double quotes""" if you use any backslashes in your docstrings. For Unicode docstrings, use u"""Unicode triple-quoted strings""" .

More, you missed one newline between your imports and the first function. It's not such a big deal but I thought it's worth mentioning it.

In this line:

...
return file_.read().replace("\"", "").split(",")

You can use single quotes to get rid of the escape character \:

return file_.read().replace('"', '').split(',')

You can also omit the read file mode as that's the default mode when you read a file:

with open(file_path) as file_:
    ...

There's more than one place where you wrote:

something = list(string)

Instead of the situation where you sorted the list, you don't need list(string) because you can already iterate a string just fine.

###Use enumerate() more often.

You can rewrite your get_alpha_values() function like this:

def get_alpha_values() -> Dict:
    alpha_values = {}
    for index, letter in enumerate(string.ascii_uppercase, 1):
        alpha_values[letter] = index
    return alpha_values

Enumerate takes a second argument which lets you start from whatever position you want (in our case, that would be 1).

We can also make use of the get() method of the dicts and make your get_word_alpha_value() more straightforward:

def get_word_alpha_value(word: str, alpha_values: Dict) -> int:
    return sum([alpha_values.get(letter, 0) for letter in word])

The get method of a dict (like for example characters) works just like indexing the dict, except that, if the key is missing, instead of raising a KeyError it returns the default value (if you call .get with just one argument, the key, the default value is None)

Nice PEP8 compliant code, Phrancis. Good job! I only have two comments to make regarding that: you usually have to use triple-double quoted strings when it comes to docstrings. From the docs (PEP257):

For consistency, always use """triple double quotes""" around docstrings. Use r"""raw triple double quotes""" if you use any backslashes in your docstrings. For Unicode docstrings, use u"""Unicode triple-quoted strings""" .

More, you missed one newline between your imports and the first function. It's not such a big deal but I thought it's worth mentioning it.

In this line:

...
return file_.read().replace("\"", "").split(",")

You can use single quotes to get rid of the escape character \:

return file_.read().replace('"', '').split(',')

You can also omit the read file mode as that's the default mode when you read a file:

with open(file_path) as file_:
    ...

There's more than one place where you wrote:

something = list(string)

Instead of the situation where you sorted the list, you don't need list(string) because you can already iterate a string just fine.

###Use enumerate() more often.

The enumerate() function adds a counter to an iterable. That said, you can rewrite your get_alpha_values() function like this:

def get_alpha_values() -> Dict:
    alpha_values = {}
    for index, letter in enumerate(string.ascii_uppercase, 1):
        alpha_values[letter] = index
    return alpha_values

Enumerate takes a second argument which lets you start from whatever position you want (in our case, that would be 1).

We can also make use of the get() method of the dicts and make your get_word_alpha_value() more straightforward:

def get_word_alpha_value(word: str, alpha_values: Dict) -> int:
    return sum([alpha_values.get(letter, 0) for letter in word])

The get method of a dict (like for example characters) works just like indexing the dict, except that, if the key is missing, instead of raising a KeyError it returns the default value (if you call .get with just one argument, the key, the default value is None)

added 703 characters in body
Source Link
Grajdeanu Alex
  • 9.3k
  • 4
  • 32
  • 71

Nice PEP8 compliant code, Phrancis. Good job! I only have two comments to make regarding that: you usually have to use triple-double quoted strings when it comes to docstrings. From the docs (PEP257):

For consistency, always use """triple double quotes""" around docstrings. Use r"""raw triple double quotes""" if you use any backslashes in your docstrings. For Unicode docstrings, use u"""Unicode triple-quoted strings""" .

More, you missed one newline between your imports and the first function. It's not such a big deal but I thought it's worth mentioning it.

In this line:

...
return file_.read().replace("\"", "").split(",")

You can use single quotes to get rid of the escape character \:

return file_.read().replace('"', '').split(',')

You can also omit the read file mode as that's the default mode when you read a file:

with open(file_path) as file_:
    ...

There's more than one place where you wrote:

something = list(string)

Instead of the situation where you sorted the list, you don't need list(string) because you can already iterate a string just fine.

###Use enumerate() more often.

You can rewrite your get_alpha_values() function like this:

def get_alpha_values() -> Dict:
    alpha_values = {}
    for index, letter in enumerate(string.ascii_uppercase, 1):
        alpha_values[letter] = index
    return alpha_values

Enumerate takes a second argument which lets you start from whatever position you want (in our case, that would be 1).

We can also make use of the get() method of the dicts and make your get_word_alpha_value() more straightforward:

def get_word_alpha_value(word: str, alpha_values: Dict) -> int:
    return sum([alpha_values.get(letter, 0) for letter in word])

The get method of a dict (like for example characters) works just like indexing the dict, except that, if the key is missing, instead of raising a KeyError it returns the default value (if you call .get with just one argument, the key, the default value is None)

Nice PEP8 compliant code, Phrancis. Good job! I only have two comments to make regarding that: you usually have to use triple-double quoted strings when it comes to docstrings. From the docs (PEP257):

For consistency, always use """triple double quotes""" around docstrings. Use r"""raw triple double quotes""" if you use any backslashes in your docstrings. For Unicode docstrings, use u"""Unicode triple-quoted strings""" .

More, you missed one newline between your imports and the first function. It's not such a big deal but I thought it's worth mentioning it.

In this line:

...
return file_.read().replace("\"", "").split(",")

You can use single quotes to get rid of the escape character \:

return file_.read().replace('"', '').split(',')

You can also omit the read file mode as that's the default mode when you read a file:

with open(file_path) as file_:
    ...

There's more than one place where you wrote:

something = list(string)

Instead of the situation where you sorted the list, you don't need list(string) because you can already iterate a string just fine.

###Use enumerate() more often.

You can rewrite your get_alpha_values() function like this:

def get_alpha_values() -> Dict:
    alpha_values = {}
    for index, letter in enumerate(string.ascii_uppercase, 1):
        alpha_values[letter] = index
    return alpha_values

Enumerate takes a second argument which lets you start from whatever position you want (in our case, that would be 1).

Nice PEP8 compliant code, Phrancis. Good job! I only have two comments to make regarding that: you usually have to use triple-double quoted strings when it comes to docstrings. From the docs (PEP257):

For consistency, always use """triple double quotes""" around docstrings. Use r"""raw triple double quotes""" if you use any backslashes in your docstrings. For Unicode docstrings, use u"""Unicode triple-quoted strings""" .

More, you missed one newline between your imports and the first function. It's not such a big deal but I thought it's worth mentioning it.

In this line:

...
return file_.read().replace("\"", "").split(",")

You can use single quotes to get rid of the escape character \:

return file_.read().replace('"', '').split(',')

You can also omit the read file mode as that's the default mode when you read a file:

with open(file_path) as file_:
    ...

There's more than one place where you wrote:

something = list(string)

Instead of the situation where you sorted the list, you don't need list(string) because you can already iterate a string just fine.

###Use enumerate() more often.

You can rewrite your get_alpha_values() function like this:

def get_alpha_values() -> Dict:
    alpha_values = {}
    for index, letter in enumerate(string.ascii_uppercase, 1):
        alpha_values[letter] = index
    return alpha_values

Enumerate takes a second argument which lets you start from whatever position you want (in our case, that would be 1).

We can also make use of the get() method of the dicts and make your get_word_alpha_value() more straightforward:

def get_word_alpha_value(word: str, alpha_values: Dict) -> int:
    return sum([alpha_values.get(letter, 0) for letter in word])

The get method of a dict (like for example characters) works just like indexing the dict, except that, if the key is missing, instead of raising a KeyError it returns the default value (if you call .get with just one argument, the key, the default value is None)

added 703 characters in body
Source Link
Grajdeanu Alex
  • 9.3k
  • 4
  • 32
  • 71
Loading
Source Link
Grajdeanu Alex
  • 9.3k
  • 4
  • 32
  • 71
Loading