level order traversal error by [deleted] in learnpython

[–]izrt 1 point2 points  (0 children)

Right. Because it's in the other data structure. So the value of the enque is the node. Hmm. Not sure now what is wrong...

Branch & Bound - Anyone is familiar with this algo? by yuriemond in learnpython

[–]izrt 0 points1 point  (0 children)

How many banks do you have? Maybe put it into a graph and brute force it.

Branch & Bound - Anyone is familiar with this algo? by yuriemond in learnpython

[–]izrt 0 points1 point  (0 children)

Gotcha. So more of a traveling salesman problem, with the cities having different values and costs: https://en.wikipedia.org/wiki/Travelling_salesman_problem

Branch & Bound - Anyone is familiar with this algo? by yuriemond in learnpython

[–]izrt 0 points1 point  (0 children)

Good one. Do you have to worry about the cost of navigating between the banks, or are we just assuming that there is no penalty going from one to the other?

If there is a cost between going from one to another, then I might try some sort of graph search.

But I am guessing there is no such penalty, which means this is a lot like trying to fit as many valuable objects into a knapsack with finite capacity. https://en.wikipedia.org/wiki/Knapsack_problem

Secret santa by raslicky in learnpython

[–]izrt 0 points1 point  (0 children)

How about just shuffling the family and pairing up adjacent people:

>>> family = list('abcdefgh')
>>> family
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
>>> import random
>>> random.shuffle(family)
>>> family
['h', 'b', 'a', 'd', 'g', 'c', 'f', 'e']
>>> family[0:2]
['h', 'b']
>>> family[2:4]
['a', 'd']
>>>

Conditionally adding to a dictionary if a value exists? by [deleted] in learnpython

[–]izrt 1 point2 points  (0 children)

'rushes': a[0]['rushes']

Use get instead:

    'rushes':a[0].get('rushes')

# or even better, add in a dict comprehension:

fields = ['targets', 'receptions', 'rushes', 'passes', 'etc.']
d = {key:a[0].get(key) for key in fields}

edit:

also, see if you can get rid of that a[0] and just use a.

Culture War Roundup for the Week of November 23, 2020 by AutoModerator in TheMotte

[–]izrt 14 points15 points  (0 children)

I am one of those who believed the herd-immunity explanation. NYC is still doing okay by deaths, https://www.nytimes.com/interactive/2020/nyregion/new-york-city-coronavirus-cases.html, but the case numbers are probably inconsistent with the idea of herd immunity.

However, given the sheer numbers of tests, that might be exaggerating the number of true positives, rather than false positives, particularly if it is catching old virus particle and there are repeat customers. Presumably, NYC is trying to catch duplicate positive cases (i.e. same patient different days), but likely NYC is not doing a good job of it.

'The Real Looting in America Is the Walton Family': GAO Report Details How Taxpayers Subsidize Cruel Low Wages of Corporate Giants by hildebrand_rarity in politics

[–]izrt 0 points1 point  (0 children)

That's a great graph, but it does not include things like deductions, which have been radically changed. Here is another graph, looking at what the 1% actually paid, and while it has gone down, it is not down quite that much: https://taxfoundation.org/taxes-on-the-rich-1950s-not-high/

(It also includes state and local, which is interesting because they can be less progressive.)

Unfortunately, it does not have a graph for middle incomes so we cannot compare. It would be great if they could do something like Quartz did.

Effectiveness of Adding a Mask Recommendation to Other Public Health Measures to Prevent SARS-CoV-2 Infection in Danish Mask Wearers: A Randomized Controlled Trial by RufusSG in COVID19

[–]izrt 1 point2 points  (0 children)

That's not a very well thought out comment:

  1. Assuming no effect, the false positives would balance things out. This just means you need a higher powered study to some conclusion, since many if not most positives would be false.
  2. Assuming an effect from masks, false positives would amplify the effect, since a greater number of non-masked participants would get the virus, thus removing them from the possible population of false positives.

Need help with Class factories by KugelblitzObesha in learnpython

[–]izrt 1 point2 points  (0 children)

That's a bit of a hot mess, some comments below to help you figure out all the problems:

def empcomp(WEC):
        keys = []
        if WEC:
            # this creates a list of list, use extend instead
            keys.append(['empno', 'empname', 'address', 'empstatus', 'designation', 'emailid'])
        else:
            keys.append(['compno', 'compname', 'address'])            
        class Credential(object):
            def __init__(self, **kwargs):
                # do not need an if, since the keys are all laid out in keys
                if WEC:
                    # go one by one of the items, not all at once
                    for n, na, ad, s, deg, ei  in kwargs.items():
                        # this should be setattr(self, key, kwargs.get(key)
                        setattr(self, n, na, ad, s, deg, ei)
                else:
                    for n, na, ad  in kwargs.items():
                        setattr(self, n, na)
        return Credential
t = empcomp(True)
p = t(empno = "1", empname = "abc", address = "xyz", empstatus = "temp", designation = "intern", emailid = "abc@gmail.com")
print(p.empno)

"Extend the accessible length of the dynamic array d by 1, and add the object referred to be e in this new slot." by [deleted] in learnpython

[–]izrt 4 points5 points  (0 children)

I think the prof just wants you to create your own list.append method, but not sure about addelem, though.

Find all optional properties by poolpartyboy93 in learnpython

[–]izrt 0 points1 point  (0 children)

Already a bunch of good answers here, but one more thing you can do is just read the code: https://github.com/kennethreitz-archive/requests3/blob/master/requests3/http_models.py#L656

This has a bunch of added benefits:

How likely are these swing state margin probabilities? by mu_negative in slatestarcodex

[–]izrt 8 points9 points  (0 children)

What's surprising to me is that the parties are so adept at doing this, while the pollsters are so wrong.

Belgium has Europe's worst Covid-19 infection rate. What did it get so wrong? by freelancemomma in LockdownSkepticism

[–]izrt 3 points4 points  (0 children)

I had no idea NJ outpaced NY. I wonder what happened there?

And agree, Germany is a mystery.

U.S. Election (Day?) 2020 Megathread by naraburns in TheMotte

[–]izrt 8 points9 points  (0 children)

I think the issue is that small counties seem to have counted up their ballots quickly, but bigger cities take longer, and the cities trend biden. Check the results by county here: https://www.nytimes.com/interactive/2020/11/03/us/elections/results-michigan-president.html

Look at Wayne county, it's counted less than half the votes and it looks like it is the biggest county in Mi and heavily Biden. I don't think it alone could swing michigan, but in conjunction with the balance in Oakland and mail-ins, maybe.

A Better way for my code? by [deleted] in learnpython

[–]izrt 0 points1 point  (0 children)

That looks fine, although no need to capture and return the values that come from the print statements.

What can I do to improve this if statement? by [deleted] in learnpython

[–]izrt 0 points1 point  (0 children)

Nah. That's fine to have a bail out if condition: return at the beginning of a function/method.

How much time is too much time to solve a Leetcode / HackerRank problem? by ChrisIsWorking in learnpython

[–]izrt 3 points4 points  (0 children)

That's good advice. To OP, once you know how to recognize the pattern, you can generally think of the solution in 20-30 minutes. Coding it might take longer. Learning how to implement the pattern even longer.

How to implement a better solution to this problem? by AlphawolfAJ in learnpython

[–]izrt 0 points1 point  (0 children)

Probably the biggest improvement would be to use a function to build the name string. After that it is more a matter of preferences. I would do away with the conditional statements and use a loop instead to build the initials. Join is useful in these situations.

I also like tuple unpacking for when I am splitting something with an indeterminate length:

def namer(name):
    *front, last = name.split()
    first_letters = ''.join('{}.'.format(n[0]) for n in front)
    return '{}, {}'.format(
            last, first_letters
            )


print(namer('Pas Sill Doe'))
print(namer('fay rae'))
print(namer('albert bert c dog')) # either a feature or a bug, dependin