Skip to main content
edited body
Source Link
200_success
  • 145.7k
  • 22
  • 191
  • 481

Be consistent and pythonic in naming functions.

draw_arrow instead of drawArrow

YouUse comprehensions instead of creating empty list and appending to it in a for loop. It's both faster and easier to read.

def translate(coords, vector):
    # Translates a list of coordinate tuples over a vector tuple
    return tuple(tuple(map(operator.add, c, vector)) for c in coords)

def mirror(coords):
    # Takes a list of coordinate tuples and mirrors it across the first element of
    #    the first tuple
    # Formula: 2 * base - original
    base = coords[0]
    double_base = tuple(map(operator.mul, base, len(base) * (2,) ))
    return tuple(tuple(map(operator.sub, double_base, cord)) for c in coords)

Why have a function that returns a constant value. Why creating a variable when you can just return the value.

def get_arrow_coords():
    return [...]
# or if you worry about mutability - use tuples. They actually faster if you wouldn't try to modify them (creating new ones from old ones) a lot.

arrow_coords = ...

You can also use collections.namedtuple('Size', 'height width') instead of using plain tuples for sizes. This would improve readability a little.

And I'm not sure, but maybe you would benefit from using numpy as it seems that you're doing some matrices work.

Be consistent and pythonic in naming functions.

draw_arrow instead of drawArrow

You comprehensions instead of creating empty list and appending to it in a for loop. It's both faster and easier to read.

def translate(coords, vector):
    # Translates a list of coordinate tuples over a vector tuple
    return tuple(tuple(map(operator.add, c, vector)) for c in coords)

def mirror(coords):
    # Takes a list of coordinate tuples and mirrors it across the first element of
    #    the first tuple
    # Formula: 2 * base - original
    base = coords[0]
    double_base = tuple(map(operator.mul, base, len(base) * (2,) ))
    return tuple(tuple(map(operator.sub, double_base, cord)) for c in coords)

Why have a function that returns a constant value. Why creating a variable when you can just return the value.

def get_arrow_coords():
    return [...]
# or if you worry about mutability - use tuples. They actually faster if you wouldn't try to modify them (creating new ones from old ones) a lot.

arrow_coords = ...

You can also use collections.namedtuple('Size', 'height width') instead of using plain tuples for sizes. This would improve readability a little.

And I'm not sure, but maybe you would benefit from using numpy as it seems that you're doing some matrices work.

Be consistent and pythonic in naming functions.

draw_arrow instead of drawArrow

Use comprehensions instead of creating empty list and appending to it in a for loop. It's both faster and easier to read.

def translate(coords, vector):
    # Translates a list of coordinate tuples over a vector tuple
    return tuple(tuple(map(operator.add, c, vector)) for c in coords)

def mirror(coords):
    # Takes a list of coordinate tuples and mirrors it across the first element of
    #    the first tuple
    # Formula: 2 * base - original
    base = coords[0]
    double_base = tuple(map(operator.mul, base, len(base) * (2,) ))
    return tuple(tuple(map(operator.sub, double_base, cord)) for c in coords)

Why have a function that returns a constant value. Why creating a variable when you can just return the value.

def get_arrow_coords():
    return [...]
# or if you worry about mutability - use tuples. They actually faster if you wouldn't try to modify them (creating new ones from old ones) a lot.

arrow_coords = ...

You can also use collections.namedtuple('Size', 'height width') instead of using plain tuples for sizes. This would improve readability a little.

And I'm not sure, but maybe you would benefit from using numpy as it seems that you're doing some matrices work.

added 269 characters in body
Source Link

Be consistent and pythonic in naming functions.

draw_arrow instead of drawArrow

You comprehensions instead of creating empty list and appending to it in a for loop. It's both faster and easier to read.

def translate(coords, vector):
    # Translates a list of coordinate tuples over a vector tuple
    return tuple(tuple(map(operator.add, c, vector)) for c in coords)

def mirror(coords):
    # Takes a list of coordinate tuples and mirrors it across the first element of
    #    the first tuple
    # Formula: 2 * base - original
    base = coords[0]
    double_base = tuple(map(operator.mul, base, len(base) * (2,) ))
    return tuple(tuple(map(operator.sub, double_base, cord)) for c in coords)

Why have a function that returns a constant value. Why creating a variable when you can just return the value.

def get_arrow_coords():
    return [...]
# or if you worry about mutability - use tuples. They actually faster if you wouldn't try to modify them (creating new ones from old ones) a lot.

arrow_coords = ...

You can also use collections.namedtuple('Size', 'height width') instead of using plain tuples for sizes. This would improve readability a little.

And I'm not sure, but maybe you would benefit from using numpy as it seems that you're doing some matrices work.

Be consistent and pythonic in naming functions.

draw_arrow instead of drawArrow

You comprehensions instead of creating empty list and appending to it in a for loop. It's both faster and easier to read.

def translate(coords, vector):
    # Translates a list of coordinate tuples over a vector tuple
    return tuple(tuple(map(operator.add, c, vector)) for c in coords)

def mirror(coords):
    # Takes a list of coordinate tuples and mirrors it across the first element of
    #    the first tuple
    # Formula: 2 * base - original
    base = coords[0]
    double_base = tuple(map(operator.mul, base, len(base) * (2,) ))
    return tuple(tuple(map(operator.sub, double_base, cord)) for c in coords)

Why have a function that returns a constant value. Why creating a variable when you can just return the value.

def get_arrow_coords():
    return [...]
# or if you worry about mutability - use tuples. They actually faster if you wouldn't try to modify them (creating new ones from old ones) a lot.

arrow_coords = ...

Be consistent and pythonic in naming functions.

draw_arrow instead of drawArrow

You comprehensions instead of creating empty list and appending to it in a for loop. It's both faster and easier to read.

def translate(coords, vector):
    # Translates a list of coordinate tuples over a vector tuple
    return tuple(tuple(map(operator.add, c, vector)) for c in coords)

def mirror(coords):
    # Takes a list of coordinate tuples and mirrors it across the first element of
    #    the first tuple
    # Formula: 2 * base - original
    base = coords[0]
    double_base = tuple(map(operator.mul, base, len(base) * (2,) ))
    return tuple(tuple(map(operator.sub, double_base, cord)) for c in coords)

Why have a function that returns a constant value. Why creating a variable when you can just return the value.

def get_arrow_coords():
    return [...]
# or if you worry about mutability - use tuples. They actually faster if you wouldn't try to modify them (creating new ones from old ones) a lot.

arrow_coords = ...

You can also use collections.namedtuple('Size', 'height width') instead of using plain tuples for sizes. This would improve readability a little.

And I'm not sure, but maybe you would benefit from using numpy as it seems that you're doing some matrices work.

added 340 characters in body
Source Link

Be consistent and pythonic in naming functions.

draw_arrow instead of drawArrow

You comprehensions instead of creating empty list and appending to it in a for loop. It's both faster and easier to read.

def translate(coords, vector):
    # Translates a list of coordinate tuples over a vector tuple
    return tuple(tuple(map(operator.add, c, vector)) for c in coords)

def mirror(coords):
    # Takes a list of coordinate tuples and mirrors it across the first element of
    #    the first tuple
    # Formula: 2 * base - original
    base = coords[0]
    double_base = tuple(map(operator.mul, base, len(base) * (2,) ))
    return tuple(tuple(map(operator.sub, double_base, cord)) for c in coords)

Why have a function that returns a constant value. Why creating a variable when you can just return the value.

def get_arrow_coords():
    return [...]
# or if you worry about mutability - use tuples. They actually faster if you wouldn't try to modify them (creating new ones from old ones) a lot.

arrow_coords = ...

Be consistent and pythonic in naming functions.

draw_arrow instead of drawArrow

You comprehensions instead of creating empty list and appending to it in a for loop. It's both faster and easier to read.

def translate(coords, vector):
    # Translates a list of coordinate tuples over a vector tuple
    return tuple(tuple(map(operator.add, c, vector)) for c in coords)

def mirror(coords):
    # Takes a list of coordinate tuples and mirrors it across the first element of
    #    the first tuple
    # Formula: 2 * base - original
    base = coords[0]
    double_base = tuple(map(operator.mul, base, len(base) * (2,) ))
    return tuple(tuple(map(operator.sub, double_base, cord)) for c in coords)

Be consistent and pythonic in naming functions.

draw_arrow instead of drawArrow

You comprehensions instead of creating empty list and appending to it in a for loop. It's both faster and easier to read.

def translate(coords, vector):
    # Translates a list of coordinate tuples over a vector tuple
    return tuple(tuple(map(operator.add, c, vector)) for c in coords)

def mirror(coords):
    # Takes a list of coordinate tuples and mirrors it across the first element of
    #    the first tuple
    # Formula: 2 * base - original
    base = coords[0]
    double_base = tuple(map(operator.mul, base, len(base) * (2,) ))
    return tuple(tuple(map(operator.sub, double_base, cord)) for c in coords)

Why have a function that returns a constant value. Why creating a variable when you can just return the value.

def get_arrow_coords():
    return [...]
# or if you worry about mutability - use tuples. They actually faster if you wouldn't try to modify them (creating new ones from old ones) a lot.

arrow_coords = ...
Source Link
Loading