#๐ Someone help me to make this code more efficient.
26 messages ยท Page 1 of 1 (latest)
@oblique meteor
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.
!code
its over 2000 characters
!paste
If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/
After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.
Or upload it to Github.
I uploaded it
And what do you mean by "efficient"? Make the code run faster, or to make the code more readable?
More readable, more concise, doing more with less
This is actually a great opportunity to learn how to reduce duplication.
Look at all your functions. They're all basically identical. That's not great, since if you want to add functionality later, you may need to modify them all, and every time you want to add a new album, you need to make another copy.
man i should of used a dictionary ๐ญ
and then looped over it
but i dont know how so i had to code like I was paid per line
I have a vision for the code but it just dosent click
Dictionary for every album song pair and the code that allows songs to be played and loops over it
What I meant is this. Notice what the differences are between these functions: https://www.diffchecker.com/NoGjeaRg/
Basically nothing. It's just the list of song names.
In cases like these, pass the data that differs in as an argument
Then you'd have one function called something like handle_songlist, and you give it the list of songs to manage.
oh wow
I'd encourage you to try making that refactor. But you're right that a dictionary would help here. A dictionary that maps album identifier to song list would make this cleaner.
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.