Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAlex Life
16,114 Pointsthis seems like a lot of trouble
Besides the off the wall variable names, why does this seem more complicated than it should be? Is there an easier way? What is the consensus on my codes? Good? Garbage?
def num_teachers(know_it_alls):
brainiacs = 0
for brains in know_it_alls:
brainiacs +=1
return(brainiacs)
def num_courses(know_it_alls):
brain_drain = 0
drains = []
drains.append(know_it_alls.values())
for drainage in drains:
for leakage in drainage:
for nimrods in leakage:
brain_drain +=1
return(brain_drain)
def courses(know_it_alls):
imaneagle = []
cawcaw = []
imaneagle.append(know_it_alls.values())
for eggs in imaneagle:
for leakage in eggs:
for birds in leakage:
cawcaw.append(birds)
return(cawcaw)
def most_courses(know_it_alls):
armored_halfling = []
harbinger_of_peace = []
dwarves_of_the_mountain = []
for halflings in know_it_alls:
armored_halfling.append(halflings)
harbinger_of_peace.append(know_it_alls.values())
for bilbos in harbinger_of_peace:
for the_precious in bilbos:
dwarves_of_the_mountain.append(len(the_precious))
the_true_king = max(dwarves_of_the_mountain)
all_hail = dwarves_of_the_mountain.index(the_true_king)
your_ruler = armored_halfling[all_hail]
return(your_ruler)
def stats(know_it_alls):
items_to_be_canned = []
peaches = []
carrots = []
for items in know_it_alls:
items_to_be_canned.append(items)
peaches.append(know_it_alls.values())
for slices in peaches:
for cans in slices:
carrots.append(len(cans))
pears = [list(squash) for squash in zip(items_to_be_canned,carrots)]
return(pears)
1 Answer
Steven Parker
231,248 PointsI wouldn't say "garbage", in fact this looks to me like a well-executed deliberate effort at code obfuscation. I've seen it with other languages, but this is the first example I've seen in Python. Generally, Python developers adopt a style that is naturally concise and clear.
This code is clever, but I think a more conventional approach would be quite a bit easier and it would certainly produce much more compact code.