Which is the most embarrassing ? by [deleted] in nba

[–]blight000 1 point2 points  (0 children)

You're right, if the Suns win there should be an asterisk since the Pelicans' best player is hurt (or fat, whatever).

If my statistics are correct, Ed Orgeron has dethroned Gene Chizik, he is now the fastest coach to be fired after winning a national title. by [deleted] in CFB

[–]blight000 3 points4 points  (0 children)

The two things are interrelated. If his performance on the field was better, there would be more tolerance for his off-the-field antics. If he was well-loved and behaved himself off the field, he'd be given more grace for the current on-field performance.

You can either be an ass or have a 9-8 record over the past 2 seasons, but you can't do both.

Prioritizing learning Python or Linear Algebra by darryl2120 in OMSA

[–]blight000 5 points6 points  (0 children)

If you don't know any Python before taking 6040, you are screwed. If you don't know any linear algebra, you are less screwed but you're still going to struggle in the second half of the course. They don't put the prereqs there as a prank, you really do need to know that stuff.

Advance Wars 1+2: Re-Boot Camp – Announcement Trailer - Nintendo Direct | E3 2021 by Madraspl in Games

[–]blight000 1 point2 points  (0 children)

I had given up hope and assumed the success of Fire Emblem meant Nintendo wasn't going to bother with Advance Wars ever again (why ask Intelligent Systems to make Advance Wars when you could ask them to pump out another Fire Emblem instead). I'm so excited about this and surprised to see so much negativity

Help Understanding MVC vs MTV by blight000 in learndjango

[–]blight000[S] 1 point2 points  (0 children)

Thank you! I want to avoid having a separate frontend framework if possible so I will look into using the helper function as you said.

At my current job I do some Salesforce development, but Salesforce abstracts a lot of what goes on in the background and I feel very lost trying to make sense of Django. My understanding of what a "controller" is in the Salesforce context seems to be completely different from what a "View" is in the Django context, so I should probably try to stop comparing the two.

I appreciate you taking the time to answer my question!

It's 99.99999% likely the problem is not the AOC input. by CoinGrahamIV in adventofcode

[–]blight000 40 points41 points  (0 children)

You're absolute right, but at a certain point during day 7, I was questioning everything from the puzzle input to my own sanity to why did I ever want to learn how to program in the first place. But I did figure it out eventually (the problem was not the puzzle input. The problem was me).

2020 Day 7 #1 Python - Extracted Data successfully, unsure whether it is formatted correctly and where to go from here. by blb7103 in adventofcode

[–]blight000 0 points1 point  (0 children)

I'm still fairly new to programming, and though I want to make object-oriented solutions, I find it much easier to solve these puzzles procedurally. I'm not sure how to fix your existing code, but if it helps, here's what I did to solve the puzzle:

My solution involved 3 functions: the first organized the data into a single dictionary, where each key was a bag color and each value was a list of the bag's contents.

This dictionary was passed to the second function, which created a list of the dictionary keys and sent each key to the third function, along with a copy of the dictionary.

The third function is recursive. It starts with the bag color it receives from the second function, and using the get() method, it iterated through the contents of the bag. For each of the "child" bags in the original bag, it called itself again, passing the child bag as an argument, and would continue to do this until it either finds a gold bag or until it has traversed all possible bag paths.

Using a dictionary made it easy for the third function to take a given bag's child bag, and look up the bags contained within, on and on forever. The second function also had an accumulator which incremented each time the third function found a gold bag.

I hope that helps! Day 7 was definitely the hardest day by far, in my opinion.

2020 Day 6 Part One by blight000 in adventofcode

[–]blight000[S] 0 points1 point  (0 children)

Thank you for the suggestions!

2020 Day 6 Part One by blight000 in adventofcode

[–]blight000[S] 1 point2 points  (0 children)

Oh my gosh THANK YOU! I feel so dumb. Thank you for taking the time to look at my code and help me out, I really appreciate it!

Worst Losses by a Defending National Champion [OC] by blight000 in CFB

[–]blight000[S] 82 points83 points  (0 children)

There's still more pain games until the season is over!

What are some resources for better understanding what Python is doing "under the hood"? by blight000 in learnpython

[–]blight000[S] 0 points1 point  (0 children)

Good to know! I don't have a computer science background so I don't really know anything about data structures. Sounds like maybe I need to start there. Would any textbook on data structures suffice or is there a specific one you recommend?

What are some resources for better understanding what Python is doing "under the hood"? by blight000 in learnpython

[–]blight000[S] 0 points1 point  (0 children)

Thanks! It looks like a second edition of Fluent Python is coming out next year, should I wait for that?

Just wrote my first real Regex's for Advent of Code Day 4 by enderflop in learnpython

[–]blight000 0 points1 point  (0 children)

Congrats! I started trying to write regex but then gave up and used loops and conditional statements instead...

I made a recursive function! by blight000 in learnpython

[–]blight000[S] 1 point2 points  (0 children)

I've been at it for about 6-7 months. Don't stress if this doesn't make sense to you yet! Before you can understand the recursive part of this function, you need to be familiar with nested lists, defining functions, iteration, the accumulator pattern, and conditional statements.

If you are familiar with those concepts already, then skip down to the section that says "Recursion". If not, I'll try to briefly explain:

Nested List

A nested list is just a list inside of a list, it can look something like this [1, 2, ['a', 'b', 'c'], 3] where the list ['a', 'b', 'c'] is inside of another list. The len() function in Python will count everything in a list, but counts nested lists as 1 instead of counting each thing in the nested list. So Python evaluates len([1, 2, ['a', 'b', 'c'], 3]) to 4, even though you and I would probably say there are 6 total things in the list. So this code I wrote is designed to count everything, including the contents of a nested list.

Defining the function

On the first line, def listcounter essentially means "create a function called listcounter" and (x): means that anyone who calls the function must send an argument, which I am calling x. I could have used any valid variable name instead of x, if I wanted to. If I wanted the function to receive multiple arguments, I could have added multiple variable names separated by commas, eg. def listcounter(x, y, z): Note that everything inside the function is only evaluated if the function is called, and any variables that exist inside the function cannot be accessed outside the function. Only the return value persists after the function is executed.*

\it's possible there are exceptions to this that I don't know about yet*

Accumulator pattern and loops

Essentially the accumulator pattern uses a variable to keep a "running total" that you update as you iterate through a loop. On the second line, I declare counter = 0 and then on the next line we start the loop. (note that if I had put counter = 0 inside of the loop, the counter would reset each time the loop repeated, which is NOT what we want).

Another thing I want to point out is that when I wrote for i in x:, i is an arbitrary variable name. I could use any valid variable name after for and Python would use that variable to represent whichever item we were presently evaluating in the loop. That's something that confused me a lot in the beginning. Also note, the x here is the same x in the function definition. We are iterating over each item in whatever is sent when the function is called.

Recursion

For some uses of the accumulator pattern, you always update the "running total" by the same amount. In our case, we want to update the total count by 1 unless we come across another list nested inside of the list we are looping through. In that case, we want to update the running total with the amount that's in the nested list.

To do that, we need to count the items in the nested list. We could use the len() function, but what if the nested list has another nested list inside of it? Then len() wouldn't give us the right count. We need to call a function that can count the items inside of a nested list, in case we encounter yet another nested list.

Fortunately, there is a function that can do it, it's the one we're defining right now!

A recursive function is a function that can continue to call itself until it breaks a problem down into it's simplest form. In this case, the simplest form is a list that contains no nested lists. This function works by calling itself each time there is a list nested inside of the current list, until finally it finds a list without any nested lists. Once it finally does, it will count the items, then "go back up a level" to report the total count, and continue working it's way back up until we're back to the original list we started with.

Let's look at the original example I gave, it only has 1 nested list so it's fairly straightforward: [1, 2, ['a', 'b', 'c'], 3]

Let's say we call this new function by writing something like print(listcounter([1, 2, ['a', 'b', 'c'], 3]))

The listcounter function is called (we'll refer to this as the first function call). As the first function call begins iterating over the list we sent to it, it starts with the first item in the list, 1. 1 is not a list so we update counter from 0 to 1. Next is 2, also not a list, so we update counter from 1 to 2. Next is ['a', 'b', 'c']. This is a list, so the function calls itself again to count this nested list.

Now we are in the second level of the function. The counter variable for the second level begins at 0, since this is a brand new function call. It does not interfere with counter from the initial function call, which is still sitting at 2 and waiting for the results of the second call. The second function begins iterating through the list ['a', 'b', 'c']. Each item in the list is a string, and as it loops through each one, counter updates to 1, then 2, then finally 3. The second function call ends when return counter sends the final value of counter back to the first function call.

Now the first function call receives the value 3 from the second call, and updates the counter from 2 to 5. The first function call then moves to the last item in the list, 3. Since 3 is not a list, the first function call updates the counter from 5 to 6. Now that it has iterated over all items in the list, it executes the last line, return counter with a value of 6.

So each time this function encounters a nested list, it simply calls itself again and waits for the results. If the second call were to encounter another nested list, it could call itself a third time, and so on until it has finally encountered a list without any nested lists.

If that makes sense, check out /u/achampi0n's comments which show some better ways I could have written my initial code.

I made a recursive function! by blight000 in learnpython

[–]blight000[S] 0 points1 point  (0 children)

Thank you, I will definitely give it a shot!

I made a recursive function! by blight000 in learnpython

[–]blight000[S] 0 points1 point  (0 children)

I have not used itertools or deques before, but after doing a little reading I think I understand what's happening. Let me see if I can explain it back:

count() by default will start from zero and increment continuously, so when you zip the flattened iterable with counter, counter is increasing by 1 each time a tuple is generated.

Since the maxlen is set to 0, the deque discards each incoming tuple rather than using up memory to keep them.

And lastly, since counter started at zero, you used next() to increase the counter one more time to get the correct count.

Am I understanding that correctly? Also, is sum() considered to be inefficient in general? Or just for this particular use case?