« first day (3419 days earlier)      last day (1529 days later) » 

wim
8:00 PM
perhaps it could have been done cleaner, if they could add new syntax for this feature (which would have been warranted, I think, unlike e.g. assignment expressions which add new syntax for just another way to do same thing )
 
don't think there's much that can be done for super as long as classes are just namespaces with functions inside.
 
Hey Guys!!!
 
wim
a good no-nonsense dupe for comparison chaining is Chaining “is” operators
 
I have tried one logic. Just want to optimize the code
ids = [1,1,1,2,3,2,5,5];
m = 2

def deleteProducts(items, m):
    from collections import OrderedDict

    result = sorted(items, key = items.count, reverse = True)
    result = result[:len(result)-m]
    res =  [(el, result.count(el)) for el in result]
    return len(list(OrderedDict(res).items()))

deleteProducts(ids,m)
do you guys having any idea to optimize this code?
 
@shad0w_wa1k3r This is the updated dpaste link. Thanks
 
8:13 PM
@CJRamki this looks like a job for collections.Counter!
 
@superv I don't see a link.
 
@shad0w_wa1k3r dpaste.com/29GWJM6. Sorry I forgot to paste it.
 
what's the point of res, by the way? if you just want the count of unique, remainign elements use len(set(result)).
 
@MisterMiyagi great idea... Thanks :)
result = sorted(items, key = items.count, reverse = True) in this line I'm ordering array elements by its count. And result = result[:len(result)-m] I'm removing m elements from array. Is it possible to use Counterhere?
 
yes.
 
8:20 PM
@PaulMcG To gain access to the attributes in the parent's __init__() right?
 
even if you just use it to calculate the item counts once, instead of again for each repeated item.
 
lemme try it
I should group elements before using Counter right?
 
@superv I think you're not following how context & templates work. Your urls.py determines which view function or class is triggered when a user accesses a particular URL. After that, the view function gets the request object, along with any URL parameters. The view function then tries to get all the data related to this request (if a request is authorised, if it is a valid form submission, if it's a regular get request then just show the forms, etc.)
& after data generation / collection, it then passes it to the template for rendering (or in some cases just returns a status code or some other valid HTTP response not involving a template) in the form of a Context object so that rendered template shows meaningful data to the user.
 
@CJRamki Group what values?
 
ids array?
 
8:27 PM
In the built-in render shortcut / utility function, the dictionary that you pass (3rd argument to render), is the context that the template gets. The template only has access to a few other built-in variables apart from those defined in this dictionary, thus, if you try to render a variable that is not passed to the template, it will show up blank.
 
No, just call Counter(ids)
 
24 hours ago, by roganjosh
This doesn't illustrate an issue that's overcome to me. This doesn't illustrate with a particular case (and, my god, Aaron is fantastic with in-depth stuff). What about this? All I want is a definite example where something blows up if you don't use them
 
@Govind75 You are right, but it was a poor question. You are correct, you have to call the super class's __init__ to do the behavior defined up there, which usually involves defining some attributes or calling other initialize-time stuff. I was leading more toward "I'm in the current class __init__ method, so calling self.__init__ will be a recursive infinite loop."
 
@roganjosh It's just giving me Counter({1:1})
 
@superv In your template you try to do {% for contract in contract_list.all %}, but there is no variable contract_list being passed to the template, so the contract variable inside the forloop does not make any sense.
 
8:28 PM
@roganjosh I just noticed you had this convo yesterday. I want to add a couple of thoughts (maybe some else said the same thing, but I missed it...)
 
@AaronHall Was waiting for you to spot it :)
 
found during Aaron's regular self-stalk :P
 
Firstly, Python got along without enums for a long time, so things won't really blow up without them.
 
@roganjosh seems it is counting array of array count
 
Another point is that enums are "enumerations" (finite or indefinitely sized...)
Semantically, True and False are enumerations of bool.
In Haskell, Integers are semantically enumerations.
 
8:32 PM
@shad0w_wa1k3r Thanks for the explanation. The contract_list is the lowercase instance of the model Contract as I understood. I think I read somewhere that you can do a for loop on object_list or model_name_list, to get all the data in the model. Or maybe I understood wrongly
 
@CJRamki Can you please give me a quick verbal explanation of what you're trying to do. I can follow the steps of the code but I don't think I understand the intent
 
@roganjosh ids = [1,1,1,2,3,2,5,5]; and m=2 are inputs. So I'm trying to remove least count last m elements from array and return count of remaining ids
 
collections.Counter is perfect for this. And sorting before Counterizing is not necessary.
 
@CJRamki What did you pass to Counter? Try collections.Counter([1,1,1,2,3,2,5,5]), it should give Counter({1: 3, 2: 2, 3: 1, 5: 2}).
 
@AaronHall That's an interesting angle on it. I think "blows up" was too strong a term, but my problem is understanding something on the level of "oh, I should use xyz here" and I just couldn't grasp some tangible situation from any of the answers. In typing this, I'm still wrestling with the bool concept so I'm typing at like 10 wpm :)
 
8:40 PM
@MisterMiyagi but when I'm passing that array as a function parameter it is printing Counter({1: 1})
 
So, if im understanding this correctly, Enum is just a fancy way of using/grouping a few global constants? stuff like HOURS_IN_DAY and MINUTES_IN_AN_HOUR ?
 
In fact, I think Booleans might be the key here. I've not had to create such an object so that's why I've not found some parallel. That's starting to untangle into some sense
 
Just about the only thing i could imagine after reading all that. disclaimer though, 10 minutes ago, i was happy ignorant to the existance of enums. :P
 
@CJRamki That list does not return what you say it does:
import collections
collections.Counter([1,1,1,2,3,2,5,5])
Out[3]: Counter({1: 3, 2: 2, 3: 1, 5: 2})
 
@superv That might in the case of the generic view (ListView maybe, not sure) but not for any regular view functions. You usully have to pass things explicitly.
 
8:42 PM
Does someone know if you can catch Exceptions in middlewares in Django?
 
@PaulMcG It is working fine as expected when I'm passing array directly to Counter(). But, When I'm passing it as a parameter, it is returning Counter({1: 1})
 
if you are trying this in a REPL, make sure that the variables still have the value you think they do.
 
@CJRamki that sentence didn't make sense to me.
 
@CJRamki as a parameter to what?
 
function parameter
 
8:44 PM
No actually, that helps not at all
 
@AaronHall Thank you for that. It's opened it up conceptually for me and I think I'll be able to reason about them much better now :)
 
@PaulMcG Sorry, I meant function argument
def deleteProducts(items, m)
 
yes, but still doens't help. as a parameter/function parameter/function argument to what?
 
@shad0w_wa1k3r You are very right. Now that I iterate through the contract I could see the data. Thanks so much for your patience.
 
def a_function_that_counts(list_of_numbers):
  ...:     return collections.Counter(list_of_numbers)
  ...:
print(a_function_that_counts([1,1,1,2,3,2,5,5]))
Counter({1: 3, 2: 2, 5: 2, 3: 1})
 
8:46 PM
I'm writing my logic as a function, and passing that array as a argument to that function
 
# this one works
ids = [1,1,1,2,3,2,5,5]
m = 2

def deleteProducts(items, m):
    counts = collections.Counter(items)
    result = sorted(items, key=counts.__getitem__, reverse = True)
    result = result[:len(result)-m]
    return len(set(result))

deleteProducts(ids,m)
 
@superv Whenever in doubt even after enough troubleshooting, double-check your assumptions :)
 
What does that function signature (just the "def" line) look like? And how are you calling the function? What does that call statement look like?
 
@roganjosh very cool.
 
@PaulMcG Wait.. Got it... Missed some where in debugging...
 
8:48 PM
Always... no, Never forget to check your references
@MisterMiyagi key=counts.get looks prettier to me
 
@shad0w_wa1k3r Aye! Aye! boss :)
 
So far, I'm 3-for-3 here in the office with the latest "Come tell me what I'm doing wrong, and why my Python code isn't doing what I want" solved by "The code you are looking at in the IDE is not the code you are running"
 
@shad0w_wa1k3r So if i am adding another model, I have to pass it to the template from the context i guess? My next challenge is to make it a multipage form with different models. Do you have an idea about how to implement that?
 
@ParitoshSingh I found it made some sense in a Java (kotlin) context but I just really struggled to put it in a Python context at all. This is a big part of trying another language properly because I think there's a barrier I can't get over in self-learning now about software design
 
@superv Yes, you have to explicitly pass data from all models you want to show through the context. Multi-page can either be done with multiple view functions (probably ideal) or single view function that handles the different steps with some URL parameter or maybe hidden form input.
 
8:56 PM
@ParitoshSingh that's not to push you into kotlin specifically, just an endorsement for your plan to get into another language in general :)
 
Aye, that is a good shout, let's just hope i can make myself get around to it eventually :P hopefully sooner rather than later
 
@shad0w_wa1k3r I will give the multiple view function a try, Hopefully i will be able to get it to work. Have you read about a tool called formtools? I read it does that. any idea?
 
ps. it won't be kotlin though. ducks and hides
 
@superv good luck. No, I don't know about formtools.
 
@shad0w_wa1k3r Thanks man. You have been kind to me :)
 
9:00 PM
you're welcome
 
@ParitoshSingh You've gotta let me know what you settle on in the end, though! I'm hedging my bets here :)
 
Would be interesting to see if what i end up with was on your radar or not. ;) I have a slight suspicion you already know it
even though i don't yet!
 
I weighed a lot of stuff up; I really toy with the idea of C++ but it just looks like a pain in the backside and I can't devote more than maybe 10% of my working time to learning something else
Plus, Cython should probably trump C++ since it's a quick conversion... if I can ever get the compiler to work. Years of working with PATH and I still struggle to set it up; Commercial anti-virus on Windows is just demonic and every approach just smashes me right into issues
Plus, I got reprimanded today for the t-rex gifs on my dashboard for one user, so I don't suppose they'll be supporting me at all from now on. It was nice of them to escalate the "issue" internally through several levels and then send an email to the guy just under the MD today with a screenshot. I know the reason it took so long; he's had to monitor the PC remotely for days until this particular user logged in, so he could printscreen
 
That sounds..uh..fun.
 
They do very important stuffs, you see :P The reprimand wasn't so bad, but I know pretty well that it will be the de facto excuse for IT to reject my requests
 
9:12 PM
If you don't get reprimanded once in a while, you just aren't pushing the envelope enough.
 
^
I've got the quiet satisfaction that he's had to spend all the time remotely monitoring the PC, because I hash all user passwords so they couldn't get around the fact that the user needed to log in for the template to actually render the gifs. Meanwhile, their entire system relies on flat files in plain text :P
 
wim
9:50 PM
@ParitoshSingh no, not really, because in those cases the value of the constant matters (e.g. HOURS_IN_DAY might be used in a calculation)
I also don't think the analogy of an enumeration to booleans is particularly useful or helpful, because it's also a value that you use in code
imagine that you had to do if (2 + 2 == 4) is Bools.TRUE: .... wat?
since that itself returns a bool you'd now be obliged to do if ((2 + 2 == 4) is Bools.TRUE) is Bools.TRUE): ...
 
ugh... that thing when you typo your pin to something and it locks you out... sighs
 
@JonClements Well, you just threw away your ninja precision. You've gone from being able to throw hair pins to type to pawing the keyboard
 
@roganjosh hpaerer;ohoawohwoaeonawdfibawefouiebu
I refuse that point! :p
 
The origins of Salad are becoming apparent :)
"word-salad" is also covered. Etymology is cool
@wim that wasn't what I took away from the analogy. 2 wouldn't exist in the first place because bool would reject it based on the strict subset of ints
 
wim
what did you take away from the analogy?
maybe that will help me to get it
 
10:04 PM
That. I can't really coalesce it any better than that right now. I'm just trying to shift my perspective for when I revisit it tomorrow
 
wim
(the only similarity I can see is that enums and bools are both similar to singleton pattern, but that is a similarity in implementation not in concept)
 
I'm really torn between the pair of you. Half of me thinks I have some proper epiphany in software design ready to burst forth, and the other half of me thinks it's not really useful
@JonClements Oooo. I'm gonna have to mull that one over a bit :) I've got that itch that there's a perfect song for this, but that's a great start
 
 
1 hour later…
wim
11:25 PM
I'm trying to find a GIF I posted a while back, multithreading in python. It had a dude breakdancing like crazy labelled CPU0 and all the other dudes standing around on sidelines CPU1, CPU2, CPU_N just cheering on. It was starred a tonne of times but can't find it in the stars history either ..
we have this same issue in production right now, where's that darn gif :D
 
I've got nothing, sorry
I can find non-python versions of the gif, mainly with minecraft or WoT (whatever that is (probably world of tanks))
 
11:55 PM
@wim this
I don't know how to dig up the gif, though :/ I remember it, but the best I can do is the YouTube version
 

« first day (3419 days earlier)      last day (1529 days later) »