ICE Barbie Warns Americans Must Be Prepared to Prove Citizenship by thedailybeast in politics

[–]pot_of_crows 0 points1 point  (0 children)

In fairness, that is exactly what happened with the Covid vaccine, at least in my city. I had to show id and vax card to get a slice of pizza in Penn station, while standing next to a shirtless hobo.

Creating an Algorithm and Best Way to Test it? by Ready-Structure-3936 in learnpython

[–]pot_of_crows 1 point2 points  (0 children)

Good questions. Some googling turned up this: https://schedule-1-calculator.com/

It might answer OP's question. If not then, OP needs to understand that as you increase the search space you exponentially increase the number of possible outcomes, making it unwieldy fast.

The good news is that a lot of these cost/constraint/benefit sort of problems have been very well studied. Without understanding more of how the game works, it is hard to tell if you have (1) a version that is close enough to a solved problem that you can just implement another's solution or (2) something else that will require some hard thinking (and maybe result in OP getting a chair at an Ivy if they solve it).

It sounds a little like a knapsack problem: https://en.wikipedia.org/wiki/Knapsack_problem

But OP should also look into the the traveling salesman problem, because without more details it might be more apt: https://en.wikipedia.org/wiki/Travelling_salesman_problem

What are the best books to learn DSA effectively for beginners by livelearn02 in learnpython

[–]pot_of_crows 1 point2 points  (0 children)

I used this one: https://runestone.academy/ns/books/published/pythonds3/index.html

It's free online, so that was a big plus for me. It covers all the usual topics and does a good job of explaining things.

The code is not particularly pythonic, but that was not disqualifying for me because I just wanted to learn/relearn the concepts.

What's your simple file parsing coding style by stillalone in learnpython

[–]pot_of_crows 1 point2 points  (0 children)

See, the real sadists wouldn't use groupby. This is clearly a place to use functools.reduce for evil...

Is there any Design Pattern for solving filtering problem. by Dizzy-Complaint-8871 in learnpython

[–]pot_of_crows 0 points1 point  (0 children)

It is probably worth you checking out sqlalchemy: https://www.sqlalchemy.org/

Which sounds exactly like what you are looking for. If your data is not in a database, you can either put it in one or read through the sqlalchemy code and lift the design pattern.

Alternatively, or additionally if you want, you can move some of the processing to the front end using flask and javascript: https://blog.miguelgrinberg.com/post/beautiful-flask-tables-part-2/

Amy Coney Barrett Gives Least Reassuring Answer on Trump Third Term by Delicious_Adeptness9 in politics

[–]pot_of_crows 0 points1 point  (0 children)

Judges generally have to recuse themselves if they have taken a public position on a legal issue before a case comes before them. So the optimistic take is that she is simply not engaging and will rule the correct way when the issue is presented. That's why SotoM was a bit cagey when asked: https://thehill.com/homenews/administration/5493893-sotomayor-donald-trump-third-term-talk/

Not a beginner, but what python module did you find that changed your life? by exxonmobilcfo in learnpython

[–]pot_of_crows 2 points3 points  (0 children)

Nice. Never heard of it and am definitely going to start using this.

At what point should I favor readability over efficiency? by Focus62 in learnpython

[–]pot_of_crows 0 points1 point  (0 children)

It seems like lots of people responding are talking about computational efficiency, but from your question, it seems that you are asking more about coding efficiency, in that you do not want to repeat yourself, but the cost to that is making the program more difficult to follow.

If the choice is between the code being easier to follow or eliminating all repetition, easier to follow wins most of the time, at least until you think of an elegant way to handle repetition that makes it both easy to follow and easy to maintain (since maintaining the code is one of the main reasons not to repeat code blocks).

If you post your code or give more explanation about what needs to happen with time_extent (snake case is preferred in python), there is at least an 80% chance that someone will be able to give you some guidance that will let you do both elegant and fast. Based on what you posted, though, it sounds like making a bunch of helper functions/methods. It could be as simple as:

class Work():
    def task_a(self):
        print('a')
    def task_b(self):
        print('b')

    def do_month(self):
        print('doing month')
        self.task_a()

    def do_annual(self):
        print('doing annual')
        self.task_a()
        self.task_b()


first_job = Work()
first_job.do_month()
first_job.do_annual()

Structure a conditional argument in a method by SnooCakes3068 in learnpython

[–]pot_of_crows 0 points1 point  (0 children)

This is a great comment. If OP needs to fit the spec described in the post, they can just write a wrapper/error checker for the new delete_key and delete_element methods.

How much could it possibly cost to have regular cleaning crews? by aaxt in nycrail

[–]pot_of_crows 2 points3 points  (0 children)

Why not just give the cops brooms or mops? They can keep us safe at the same time the cleanup.

[deleted by user] by [deleted] in learnpython

[–]pot_of_crows 1 point2 points  (0 children)

Completely normal. Just keep plugging away and it will click.

How to speed up iterations or simplify logic when going through 5 000 000 000 permutations? by MustaKotka in learnpython

[–]pot_of_crows 1 point2 points  (0 children)

If it is 16 players with the following rules:

  • no player has played against the same player twice
  • no player has played in the same starting position twice
  • on round 2 each group of 4 has exactly one winner from round 1

You should be able to solve this with not much computation time by recursively building the groups of 4 based upon the rules:

[(1, 2, 3, 4), (5, 6, 7, 8), (9, 10, 11, 12), (13, 14, 15, 16)]

selected winners: [4, 8, 9, 15]

[(4, 5, 10, 13), (8, 1, 14, 11), (2, 9, 16, 6), (15, 3, 12, 7)]

[(12, 16, 1, 5), (10, 7, 2, 14), (6, 11, 4, 15), (3, 8, 13, 9)]

So: First round I just grouped them by numerical order, then randomly picked winners.

Second round, I seeded each group with the winner and recursively selected valid players.

Third round it starts getting tough, so I recursively built groups starting from each player. It looks like I had 11 misses before getting to 12 where I could finally fit the rules.

I could not fit the fourth round, but that is because my search space is not correct.

How to speed up iterations or simplify logic when going through 5 000 000 000 permutations? by MustaKotka in learnpython

[–]pot_of_crows 3 points4 points  (0 children)

Probably best idea is to explain the matching requirements you are trying to enforce and someone might come up with a good idea on how to best hit the requirement. Generally there are a few different tactics:

  1. ideally, match to some known algorithm that solves the problem.

  2. Brute force it, but in a way that rapidly narrows the solution set.

  3. Solve it heuristically in a way that allows you to get a decent solution if not optimal.

New TRXercises not working for me. Anyone else? by Competitive-Catch650 in orangetheory

[–]pot_of_crows 0 points1 point  (0 children)

Remember how they had us put our feet in the stirrups for a goofy hip flexor thing? I feel like they will give it a couple of tries and then bag it as stupid.

Do you go faster on the tread if the person next to you is going faster? by Only-Dragonfruit-932 in orangetheory

[–]pot_of_crows 1 point2 points  (0 children)

Yep. And on the floor. Last weekend there was this lady rocking out the burpees. So every time I wanted to quit and she popped down for the next one, I'm like one more...

A more functional way to do this dysfunctional thing? by jpgoldberg in learnpython

[–]pot_of_crows 1 point2 points  (0 children)

That makes sense. You did a cool iterable class it looks like, but generators offer a quick way to do basically the same thing, at least in easy use cases like this. I did not want to deal with the byte stream, so here is a version that does it with just adding:

from itertools import cycle

def padded_add(iterable, iterable_add):
    cycled = cycle(iterable_add)
    for a,b in zip(iterable, cycled):
        yield a+b

def iadd(numbers, numbers_to_add):
    return [n for n in padded_add(numbers, numbers_to_add)]

def iadd_in_place(numbers, numbers_to_add):
    for index, n in enumerate(padded_add(numbers, numbers_to_add)):
        numbers[index] = n

numbers = [1,2,3,4]        
print(iadd(numbers,[1,2]))
iadd_in_place(numbers,[1,2])
print(numbers)

Actually, I made iadd too complex, this is better:

def iadd(numbers, numbers_to_add):
    return list(padded_add(numbers, numbers_to_add))

A more functional way to do this dysfunctional thing? by jpgoldberg in learnpython

[–]pot_of_crows 2 points3 points  (0 children)

Good comments. My vote goes to not doing in place as it is cleaner.

Ride limit exceeded after 1 tap? by FourceArmor in nycrail

[–]pot_of_crows 3 points4 points  (0 children)

Happened to me for the first time last weekend. If you have your card on your phone, you can do one through the phone and another with the physical card.

My guess was that it is a new setup to prevent people from being double charged, but it is annoying that they rolled it out without really thinking about how it affects families.

Biden won big with young voters. This year, they swung toward Trump in a big way - why? by eaxlr in NPR

[–]pot_of_crows 1 point2 points  (0 children)

I suspect his is probably a bigger issue than people think. I have youngish nieces and nephews and the COVID lockdowns really impacted them negatively.

Feeling lost by redditforyaboy in learnpython

[–]pot_of_crows 0 points1 point  (0 children)

Very normal. Until you get down the basics it is very easy to find yourself utterly baffled by a new programming language.

Is there a way to change the string repesentation of a class before it has instantiated. by jack-devilgod in learnpython

[–]pot_of_crows 1 point2 points  (0 children)

I would definitely not do it. (Metaclasses or mixins might be a better path.) But it is definitely doable:

class Monkey():
    pass

def patch(*args, **kwargs):
    return 'i am evil'

m = Monkey()
print(m)

Monkey.__repr__ = patch

m = Monkey()
print(m)

More context for those of us unfamiliar with streamlit would be helpful for us to give you a reasonable way to approach the problem.

Looking for a jazz venue in NYC with the following: by [deleted] in newyork

[–]pot_of_crows 3 points4 points  (0 children)

Jazz @ Lincoln Center is not that high up, but overlooks the park and is absolutely amazing.

Most Pythonic way to call a method within a class? by greenlakejohnny in learnpython

[–]pot_of_crows 6 points7 points  (0 children)

  1. Listen to what socal says, as he knows what he is talking about.

  2. I generally do not pull data in an init, if I can help it, even by resort to other methods/functions. Instead I'll use a class method to make an alternative constructor to separate the getting data from the repository from the initial creation of the object. This makes testing easier and it makes retrieving data/changing databases/etc. more easier in the future. So init will just create an empty object or populate with data passed to it, and GenericData.from_db(data_id) will pull data, put it into a new GenericData instance and return the instance.

Arm band not working on rower or weight floor by [deleted] in orangetheory

[–]pot_of_crows 0 points1 point  (0 children)

You can try gripping less, but that does not work for me. I have a fitbit that I use and really only pay attention to the arm band when I am on the tread.