0
votes

I get errors in PEP8 for many of the functions of the form:

def tweet_string(tweet):
    """Return a string representing a tweet."""
    location = tweet_location(tweet)
    point = (latitude(location), longitude(location))
    return '"{0}" @ {1}'.format(tweet_text(tweet), point)

pep8 E128: Continuation line under-indented for visual indent

and

def group_by_key(pairs):
    """Return a dictionary that relates each unique key in [key, value] pairs
    to a list of all values that appear paired with that key.

    Arguments:
    pairs -- a sequence of pairs

    >>> example = [ [1, 2], [3, 2], [2, 4], [1, 3], [3, 1], [1, 2] ]
    >>> group_by_key(example)
    {1: [2, 3, 2], 2: [4], 3: [2, 1]}
    """
    # Optional: This implementation is slow because it traverses the list of
    #           pairs one time for each key. Can you improve it?
    keys = [key for key, _ in pairs]
    return {key: [y for x, y in pairs if x == key] for key in keys}

pep8 E122: Continuation line missing indentation or outdented

How can I fix this? I've looked everywhere but can't find a solution to 122 and not sure about 128.

1

1 Answers

0
votes

The latter one could probably be fixed by reducing the summary line.

As per PEP257 (my bold):

Multi-line docstrings consist of a summary line just like a one-line docstring, followed by a blank line, followed by a more elaborate description. The summary line may be used by automatic indexing tools; it is important that it fits on one line and is separated from the rest of the docstring by a blank line.

Based on the error message, it may also work if you extra-indent the second line of the summary, but I'm not guaranteeing it.

Similarly, the first error message seems to imply that it might be okay if you leave a blank line after the docstring, so I'd try that as well.