#🔒 Refactor Code Help

10 messages · Page 1 of 1 (latest)

zinc crypt
#

I have 2x functions that basically do the same thing. almost. and just wondering if there's a better way that i don't know about.

functions display a list of character roles/jobs that you can choose from, the second func is the same thing just minus the choice from the first one, so that you cant choose same job for main and support class.

PasteBin: https://pastebin.com/byiQj7wm

crystal gobletBOT
#

@zinc crypt

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.

raw onyx
#
def select_job(job_list, taken=None):
    for index, job in enumerate(job_list, 1):
        if taken is not None and job != mainjob:
            print(......)

Something like that.

#

You could use the same loop to gather 'accepted" jobs (those printed) and provide that to get_valid_choice().

exotic pine
#

you could make a get_job function
and then call that twice to get the 2 jobs

zinc crypt
# raw onyx ```py def select_job(job_list, taken=None): for index, job in enumerate(job_...

thanks, put together:

def select_job(mainjob=None):
    for index, job in enumerate(job_list, 1):
        if mainjob is None or job != mainjob:
            print(f"{index}. {job.name}")
    # Get and validate user choice  
    selected_index = get_valid_choice(job_list)
    selected_choice = job_list[selected_index - 1]  # minus 1 to get actual index position
    return selected_choice

looks alright to me, seems to do the job

#

appreciate it

zinc crypt
#

!close

crystal gobletBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, 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.