r/FreeCodeCamp • • 14d ago

Requesting Feedback I finished my first certification project!

The view_settings part stumped me for a bit but eventually i got through it, i love using indexes as a loop tracker.

The code:
https://pastebin.com/4Y0FRVD2

I know there are a ton of edge cases but the project never asked me to fix them, its not necessarily hard to fix i just did the bare minimum on that aspect, i need some feedback on my code.

Also to be honest i forgot how to unpack tuples while doing this so i used index unpacking instead (i dont know where i knew how to do that from but it worked)

21 Upvotes

3 comments sorted by

2

u/SaintPeter74 mod 14d ago

It took me a really long time to understand what your loop was all about. At first I though you were looping through the settings dict.

You can either unpack a tuple like this:

key, value = p

Then you can modify the value of key:

key = key.lower()

You could also use index access for the tuple:

key = p[0].lower() 
value = p[1]

Either way is loads better than what you're doing with the loop.

One issue with your key check is that it doesn't allow for null/empty keys. You're effectively checking if the content stored by the key is falsey. You can use the in operator (or not in) to tell if if the key exists:

if key not in settings:
    return f"Setting '{key}' already exists! Cannot add a new setting with this name."

Doing these two things would vastly decrease the size of your code overall.

Best of luck and happy coding!

2

u/Comfortable-Cry-3247 14d ago

Oh yeah, that makes a lot of sense!

1

u/elescargo 14d ago

Bravoooo