#πŸ”’ Shorter way to tell function what type multiple arguments are

9 messages Β· Page 1 of 1 (latest)

drowsy rampart
#

Hello! I was wondering if there is a better way than what I'm doing here, as the line is quite long. Thanks!

def randomRectanglePositionsInBoard(rectWidth : int, rectHeight : int, rectAmmount : int, boardWidth : int, boardHeight : int) -> list[list[int]]:
    """
    Returns a list of coordinates [x,y], that are the top-left corners of found valid rectangles
    """
    while True:
        coordinates = []
        for _ in range(rectAmmount):
            ...
thorn rapidsBOT
#

@drowsy rampart

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

hollow jolt
#

nope, and that's my really enough arguments to be a code smell, you're good

solemn acorn
#

You can always use whitespace to your advantage πŸ™‚

def randomRectanglePositionsInBoard(
  rectWidth : int, 
  rectHeight : int, 
  rectAmmount : int, 
  boardWidth : int, 
  boardHeight : int
) -> list[list[int]]:

If you ever get yourself a formatter like black or ruff, then you can customize it and let it decide.

timber portal
#

I'd get rid of the spaces before the colons. Spaces there aren't typical.

#

And ya, I was about to post that exact code that Tekgar posted. I don't think that's necessary here yet though, personally

drowsy rampart
#

Thanks guys πŸ˜„

thorn rapidsBOT
#
Python help channel closed using Discord native close action

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.