#๐Ÿ”’ Someone help me to make this code more efficient.

26 messages ยท Page 1 of 1 (latest)

lucid oakBOT
#

@oblique meteor

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.

hallow fjord
#

!code

lucid oakBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

oblique meteor
hallow fjord
#

!paste

lucid oakBOT
#
Pasting large amounts of code

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.

hallow fjord
#

Or upload it to Github.

oblique meteor
oblique meteor
hallow fjord
#

And what do you mean by "efficient"? Make the code run faster, or to make the code more readable?

oblique meteor
hallow fjord
#

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.

oblique meteor
#

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

hallow fjord
#

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.

oblique meteor
#

oh wow

hallow fjord
#

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.

lucid oakBOT
#
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.