« first day (3750 days earlier)      last day (1181 days later) » 
00:00 - 20:0020:00 - 00:00

12:01 AM
I understand. Yes, they are numpy arrays.
 
There are quite a few anti-patterns as well. rows, cols = self.mat.shape for instance. And you're turning an array into a list of arrays for some reason. I think your code might have surprising behaviour because row[:] does not copy row.
Spoiler alert: you'll have to manually vectorize function() first.
 
@AndrasDeak The "function" only returns a number from an array.
@AndrasDeak I understand.
 
@Marco no, it returns a number when passed in a number. Vectorization means making it return an array when passed an array.
Lot of functions can't be vectorized but your use case smells like it can
 
@AndrasDeak but in the case is not necessary to pass an array to the function, I mean, I think only the function I have showed that need to be vectorized.
 
@AndrasDeak I think this is too broad, no? I can break that easily and inject for loops. I understand where you're coming from, but maybe this leave too much open ground?
 
12:11 AM
@Marco OK
@roganjosh necessary but insufficient condition
 
@Marco we can't even begin to answer that. Where is coupling defined? You can't just take a python loop and vectorize it; you might actually have to reformulate the problem in such a way that it can be vectorised
 
mat_shape = rows, cols = self.mat.shape
outputMat = (1.0-coupling) * function(self.mat, parameters, mat_shape, nit, snapshot)
for ny, nx in neighbourhood:
    outputMat += (coupling/len(neighborhood)) * function(self.mat[np.roll(np.arange(rows), -nx), np.roll(np.arange(cols), -ny)], parameters, mat_shape, nit, snapshot)
there, vectorized
 
@roganjosh Ok, I understand. Thanks. The coupling is received via the function parameter.
@AndrasDeak Wow!
 
don't thank me just yet
 
Why?
 
12:22 AM
Indeed, I don't know what's just happened
 
education in progress :P
 
I was half way through typing a message
 
@AndrasDeak Ok! :o
 
someone snuck in a Queen's neighbourhood in there
 
haha
 
12:26 AM
Do you understand how it works, @Marco?
 
let's give him some time to figure it out
 
Sure. I'm not pressing them for an answer
 
or stew in his own juice perhaps :P
 
I will not believe if this code takes, that is, 1 hour to run, it is currently taking more than a day for certain necessary parameters, but Google Colab does not let me continue running.
 
Welp, I think that's my 10 mins of yard time up. I need sleep
 
12:29 AM
Back to the quarry?
 
Bright and early!
 
@AndrasDeak It will take me a while to understand, but I swear I will try to understand. As I understand it, are you breaking your head to adjust the neighborhood?
 
@Marco I have no idea what you're asking
@roganjosh night
 
@AndrasDeak night mate
 
@AndrasDeak Or can I already thank you? If I could I would give my whole reputation as bounties. I have had this problem for weeks.
@AndrasDeak That.
 
12:30 AM
thank me when you have code that works and is vectorized
@Marco I also feel like I should state the obvious: have a small test case that runs for less than a day for you to verify that it does what you want. I think your original was buggy.
(this is true whether or not you're trying to improve your code)
 
@AndrasDeak When you told me not to thank you yet and when you clarified that it was because education was still in progress, I understood that I was still checking if the code you sent was correct.
 
@Marco yes, but the education targets something else. We'll get there eventually I hope.
don't you worry about it
 
@AndrasDeak Right.
@AndrasDeak Isn't the code you made already vectorized? Or do you have any more adjustments to make? I'm sorry, I was confused.
 
I'm done
 
@AndrasDeak Ah ok!! Thank you very much, guy. I will test it. For the good advertisements on vectorization that I have read, I hope to have a good performance improvement. If it does not improve, I believe that there is nothing to do, except to rebuild the program in another way. :P
 
12:49 AM
Oops @AndrasDeak. My fault. See:
mat_shape = rows, cols = self.mat.shape
attributeError: 'list' object has no attribute 'shape'
 
yes
 
Is a list.
 
yup
57 mins ago, by Andras Deak
Yes, an MCVE.
53 mins ago, by Andras Deak
Assuming these are numpy arrays. We'll see.
education progresses
 
Can anyone help me with python writting to a csv file in a loop please?
 
I am struggling with Pandas. I want to resample my TimeSeries to get the last record before 4pm of each day. The docs of resample state that a DateOffset can be provided, however this may only apply to specific ones.
What I got so far:

df.resample('1D').last()
 
1:02 AM
@user8607309 please don't ask for help with one-minute-old questions as per our rules
 
Ok sorry
 
1:14 AM
@AndrasDeak Yes, my fault. Sorry. I just thought that they were numpy arrays. I am checking what restructuring is needed now.
 
1:27 AM
Related to my question. I found the option to define a custom resampler. How can I get the last record before 4pm though? I am looking into numpy, is that the right approach?

df_new = df.resample('1D').apply(
    lambda arr : None if len(arr) == 0 else arr[0]
)
 
1:44 AM
cbg all, I keep getting sqlite3.OperationalError: database is locked when I run my script to update a db, its a cron job script and it happens midway, I have checked and I am sure only the script is accessing the db
it fails midway, so its not like I opened some sqlite browser or anything like some answers suggest on SO, (not threaded or multiprocess, just a single update script)
 
Here is my solution btw:
df_res = df.between_time('00:00', '16:00')
df_res = df_new.resample('1D').last()
 
can this be considered a "fix" till I can identify the issue?
while True:
    try:cur.execute(...)
    except sqlite3.OperationalError as Exception:...
    else:break
 
@AndrasDeak For now I saw only the need to adjust the beginning of the code to:
self.mat = np.array(self.mat)
mat_shape = rows, cols = self.mat.shape
@AndrasDeak Regarding the adjustment related to the mistake of being a list and not a numpy array, where should I make further adjustments?
 
why would a 40k user answer a dupe and ask the user to mark as solution? 0_o
 
@python_user how do you think they got 40k?
 
laurel, the 20 points they gain for +1 and solution wont even show on the shortened counter
 
3:07 AM
@AndrasDeak If you can adjust the vectorization of the code so that variable behaves as a list and not as an numpy array (yes, it was my fault for not giving you the correct information in the beginning), if you accept I post the question on the website, then I offer bounty and I grant the bounty to you, as I would be very grateful.
 
just have to delv that later
 
@metatoaster yup
@Marco not necessary
The code assumes numpy arrays so if you have arrays it "should work"
For some value of "should"
Meet me in the parking lot with an MCVE if it doesn't work
3
 
@AndrasDeak Ok. The problem is that in other parts of the software there seems to be a conflict with the fact that it is processed as a numpy array. So I would like it to be vectorized as a list. Would it be complicated to adjust it as a list?
 
@Marco one possible issue I can think of is that vectorization is a numpy thing.
 
Ok. That adjust (chat.stackoverflow.com/transcript/message/51419265#51419265) is sufficent, then, to acting as a numpy array?
 
3:22 AM
How many guesses do we have?
 
@AndrasDeak I solved the problem (attributeError: 'list' object has no attribute 'shape') with that code of mine, but there is a conflict for some reason, in another function of the software, complaining about the matrix's (that matrix in the code you have managed) invalid shape. So I would like to vectorize it as a list. I would have a hard time making an MCVE because the software is a little complex.
 
 
2 hours later…
5:15 AM
i know it's no longer maintained, but i'm using pycallgraph and i believe my usage should work, but it's producing an error and i'm unsure what's wrong. i have a large file of code i'm trying to profile, and i didn't want to indent it all to use pycallgraph on it, so i did
from pycallgraph import PyCallGraph
from pycallgraph.output import GraphvizOutput

with PyCallGraph(output=GraphvizOutput()):
    exec(open("./fresh-qc-sim.py").read())
(i'm aware this is probably not the. cleanest solution)
when i run this file i get the error pycallgraph.exceptions.PyCallGraphException: The command "dot" is required to be in your path.
i've checked and i do have graphviz properly installed, so i'm unsure what the issue is.
 
6:36 AM
cbg folks
 
cabbage
 
cbg
 
7:12 AM
cbg
 
7:56 AM
cbg
 
8:10 AM
hello.
So I am trying to draw a circle using PIL draw ellipse method where I need to fit an image inside it, which I can able to do. The problem is I can't seem to understand how to have thickness around the circle.
Sorry if it is not right place to ask it.
 
8:30 AM
recbg
@Abhish though it is not correct of course, it is not the same as drawing the ellipse with a stroke of certain width.
@Abhish or: pillow.readthedocs.io/en/stable/reference/… 5.3.0 onwards, there is width.
 
9:16 AM
when would you NOT call super() in inheritance with python?
 
whenever you do not need to access the immediate parent method.
In actionable terms: Do not use super to access a different method. Do not use super if the current method completely subsumes its parent method.
 
but in creating a dervied class you almost always need an __init__() which is surely overriding the parent __init__()?
5
Q: Python convention: should I normally call the super class' __init__?

Aviv CohnI read the highest rated answer to this question, and it says we should call the super class' __init__ if we need to, and we don't have to. But my question is more about convention. Should I normally, as a general rule, always call the superclass' __init__ in my class' __init__, regardless of wh...

i think this answers some of my questions in reverse
 
Consider that if a child class shares no structure ("no initialisation" -> __init__, "no construction" -> __new__) with its parent, it likely should not be a child of the parent.
 
what happens if you override the subclass __init__() but dont call super?
 
Yet you probably do not call object.__init__ in many cases, nay?
 
9:27 AM
what do you inherit then
 
Pardon? super uses inheritance. It does not define it. You can still have inheritance without super.
 
exactly
 
Hi
 
class A:
     def __init__(self):
           self.a = 1

class B(A):
      def __init__(self):
            self.a = 2
            print(a)
 
you still inherit everything as usual, but effectively supress or overwrite the parent's init. nothing else "happens", it's perfectly normal to overwrite a parent's init without running the init itself, if you want. What this means is that most likely, you were interested in the parent class's other methods and so on
 
9:30 AM
a here would be 2
but if you did
 
@Trajan Of note is that inheritance is not static in Python, due to multiple inheritance. Some class B(A) may end up being a class B(C(A)) when inherited from as class D(B, C). So avoid making assumptions like "the parent __init__ does nothing".
 
class A:
     def __init__(self):
           self.a = 1

class B(A):
      def __init__(self):
            self.a = 2
            super.__init_():
                  print(a)
            print(a)
that should be 1?
 
thats probably a syntax error
 
@ParitoshSingh yes but if you overwrite the parents init (which you mostly likely will) then if you dont call super() you wont get the attritbutes created in the parents init()?
 
correct.
 
9:34 AM
Keep in mind that __init__ is not magic. It is a regular method modifying self. If a parent __init__ modifies self by adding an attribute, skipping that __init__ in a child means the attribute is never added.
 
but then again, if you wanted to create the attributes that are being made by the parent's init, you would want to be using super in that case, wouldn't you :)
 
ok great!
class A:
     def __init__(self):
           self.a = 1

class B(A):
      def __init__(self):
            self.a = 2
            super().__init__()
            print(a)
why does that throw an error "__init__() takes 1 positional argument but 2 were given"
super() in python 3 just calls A, and its init takes no arguments?
 
Assuming that you call B() after that, this throws no errors for me.
 
a = A()
then b = B(a)
oh right, it should be b = B()
 
10:09 AM
You can definitely argue that every method should always call super and if you ever have a method that doesn't, there's something wrong with your class hierarchy. But I find that in practice, sometimes creating a super-duper 100% correct class hierarchy is just a pain in the butt
 
@metatoaster wow, deleted by jezrael
 
Rare sights :)
 
10:46 AM
hi
i need to ask a question, can i put up the code in here?
 
@ShantanuRauthan hello. Only if it's not about your new question on the main site, see sopython.com/chatroom
 
oh welp guess i shouldnt ask , @AndrasDeak thanks for the heads up
 
No worries, thanks
 
It seems as if your question has a correct answer anyway.
 
yes i remember escaping the + with \ after he commented
but it has a new error now, can i edit /paste the new error on my original question ?idk i joined today only so getting up with things
 
10:56 AM
Do not edit a question in a way that invalidates existing answers.
If you have many small questions, e.g. because you are trying to get something working step by step, chat is often more appropriate than main.
Either way, when working with regex I strongly recommend to take the time to read the docs thoroughly.
 
yes thats the thing , im trynna work it up step by step
well thanks im gonna go check my code couple more times ,will be back if i still coudnt figure out the problem
 
That's the spirit
 
haha, didn't even have to do it myself
oh, not the one I was thinking of, but we'll get there
 
Sam
11:19 AM
Hi all - I'm using the requests library to send POST requests to a Flask service. When using curl (or Postman) I'm able to send POSTs over to the server and get a response back. When I try to do it using the requests.post function in Python however, I'm consistantly getting a 500 response. I've done a bit of debugging and am I able to get the same 500 response in Postman if I change the Content-type header from application-json.
So, I looked at the headers from the requests.post call and I can see that Content-type is always being set to text/html. I've even tried explicitly adding headers but still doesn't propogate in
result = requests.post("http://0.0.0.0:5000", data=json.dumps(data), timeout=10, headers={'Content-type': 'application/json'})
Is there anything obviously wrong in my function call?
{'Server': 'gunicorn/20.0.4', 'Date': 'Thu, 21 Jan 2021 11:22:29 GMT', 'Connection': 'close', 'Content-Type': 'text/html; charset=utf-8', 'Content-Length': '290'}
Here are the headers of the request. They differ from the headers I observe in Postman in that: Content-Type: application/json, Content-Length: 128602
 
user13727121
11:45 AM
May I seek some advice from here? It's about the way I learn Python or any other programming languages that I might pick up in the future. I'm thinking that the reason I burned out so quickly when learning a new topic about Python is because of all the notes I've made or make. I would write down all the things that I've learned in the lesson just so I could refer it back to my notes if anything happens or that I might not remember the usage of a piece of code.
 
user13727121
So I'm just wondering if I'm learning Python incorrectly.
 
@CoreVisional Do you actually use those notes? I've found it best to make notes to improve my knowledge retention (do I/O with the info, not just input), not to look things up later on.
 
Yeah, during undergrad 80% of my learning was writing things down, the rest was reading them back before exams. But then again I've never learned languages like that, and I probably couldn't if I tried.
 
user13727121
12:03 PM
@MisterMiyagi Not often, but yes, I do use them. I would also do a couple of projects or exercises after every lesson to strengthen my understanding.
 
user13727121
@AndrasDeak The only downside I experience is being slightly demotivated to do so whenever I'm about to learn a new topic. But then again, I get these thoughts about the things I'll miss out or having to look things up every now and then.
 
Even when you become a python expert you'll keep looking things up in the documentation. You just don't have to (want to) keep everything in your head.
 
user13727121
It is absolutely normal, right? Like, to keep looking things up regardless of the searches. Won't it show that I haven't progressed far if I search for beginners stuff? Another reason why I wrote a bunch of essay-type notes just so I can absorb the details after every lesson..
 
Well, at the end of the day what matters is that you can solve problems you face. But I'd be surprised if you had to look up things like list.append. Not surprised if you had to look up itertools.starmap.
what you know by heart depends a lot on the tools you use or see often, so I wouldn't worry about these things as long as you can actually write code
 
12:24 PM
@AndrasDeak Assuming I haven't misunderstood something gives me far more credit than the evidence here would suggest I deserve.
I always know which is the wrong end of the stick when I find myself holding it.
 
@CoreVisional In case it helps: My most used pages of the Python docs where the builtin functions and builtin types in the past week. Special mention goes to the time module, which was a very heavy use given how I needed it to handle exactly 15 characters.
 
"In Python things don't have names, names have things." Discuss.
 
@holdenweb Can I also just agree? :P
 
Your support is reassuring. I think I might tweet that.
 
user13727121
@AndrasDeak I guess I can improve my problem-solving skill by building or working on various projects and through constant practices. I guess those notes are useless if I don't go through trials and errors, right.
 
12:33 PM
@CoreVisional yup
you'll only learn a programming language by using it
reading a tutorial helps a lot, but the more languages you know the less relevant that becomes in my experience
 
user13727121
@MisterMiyagi Yes, about the Python docs. May I ask, do most beginners read the documentation? Rarely do I find myself looking into the Python docs, even though people will always link you to the documentation after they've answered your question. I tried to understand the documentation but most of the times, I found myself wandering into topics that I have never encountered.
 
@CoreVisional I would recommend the tutorial section for reading like a book. The module and language spec should be read like a dictionary. Look up things you need, don't try to read it all.
 
user13727121
@AndrasDeak is it better to stick to one programming language first? or should I learn all the basics of a programming language, in this case, Python, and then switch to another one?
 
@CoreVisional I can't give a general answer to that, it probably depends on a lot of things. I know that for me it would be very difficult and confusing to learn two new languages in parallel. Paradigms and syntax just vary too lot.
 
@CoreVisional "learn all the basics of a programming language" is going to take a long, long time... :P
 
user13727121
12:43 PM
@MisterMiyagi Well...I might've used the docs wrongly because I tried to absorb most of it, even the things I haven't learned yet, just thought that it might be useful to remember it for future uses.
 
Honestly, there's simply too much in there, and you are likely not going to need even half of it.
Even if you do, many things get updated every now and then, so you should consult the docs anway.
"New in version" is probably a nice drinking game.
 
Rookie variant: "deprecated and will be removed in a future release"
 
user13727121
@AndrasDeak Okay, well, I almost did that. I was thinking it will help extend my understanding of different kinds of programming languages and maybe enhance my knowledge on programming (this sounds utterly absurd).
 
what matters is what works for you
 
user13727121
@MisterMiyagi The basics also include all the built-ins in Python, right? Or is that somewhere around intermediate level?
 
12:49 PM
@AndrasDeak let me just go fetch the booze...
 
@CoreVisional Most definitely not. memoryview is a builtin and nobody, I mean nobody, has ever used that thing
 
@CoreVisional I would not just restrict it to knowing the things of Python. You should be able to tell it to build basic things – your own functions and generators, and basic classes.
 
user13727121
@Aran-Fey Such coincidence. I was learning about len() function on Python docs, it shows memoryview. I remember that from not converting my iterator to list after zipping the iterables and it returned the location of the object in memory, and I did not know what was going on.
 
user13727121
@MisterMiyagi Seems like I still got a long way to go, haven't reached classes yet
 
user13727121
1:05 PM
Thank you @MisterMiyagi and @AndrasDeak for providing me with your perspectives of learning Python, it really helps a beginner significantly.
 
No problem
 
1:27 PM
Weird: I was keeping all requested data during a server call into memory inside sequences. But I notice that lookup time inside those sequences (together with storing it) has become more than just adding an extra call to the database, and letting the db do the data lookup.
 
@Marco did it break inside function() by any chance?
 
1:45 PM
My main is c# and then Python. For every test I took, I was trying to solve it with python but lately, I realize that I am more comfortable and faster with c#(because of time limits I might not get enough results as a python). But I want to switch to python. Should I keep solving it as a python or solve and pass the test as a c# and then ask for a python job?
 
uhh context?
 
@Alper not sure I understand what you're asking
 
@AndrasDeak I solve problems better with c# but I want a python job. I might not solve it in enough time with python. Should I solve them in c# and tell them I want a python job or I keep solving problems in python? Solving in c# and tell them I am good with python seems a contradiction for me.
I am applying to a generic position where language doesn't matter at start (I guess)
 
2:10 PM
Can you clarify "might not solve it in enough time" portion? Are you talking about you not being able to do some task in the time limit, or are you talking about some kind of competitive coding website test where the program must run in a certain time?
 
I am applying to a generic position where language doesn't matter at start (I guess)- then just ask if there is enough flexibility to experiment with different languages later if you feel or are they restricting the role to 1 language. You will have your answer then IMO.
 
Hey anky, hows it goin!
 
all good thanks :), long time how're you?
 
@Alper by "time limit" if you mean some code challenge website, the time out is usually because you may have a sub optimal solution, the correct algorithm in python usually have more run time than C or C++, ref : hackerrank.com/environment C time limit is 2 secs, python has 10
 
user6568562
@roganjosh I thought it was the main room, put under some new kind of restrictions
 
2:17 PM
im good too!
 
Thanks for the answers people. I cant solve it fast enough in Python as I can do it C#. It is not a runtime issue, it is me. Same problem, less practice on Python, different syntax.
 
Ah! in that case, if your goal is to work in python, and you find yourself not as fluent in it, then practice makes perfect
 
On the other hand coding challenge sites are probably not a good way to perform coding interviews, and if the system lets you get away with using a different language then it's their fault
 
@ParitoshSingh Good to know :-) Bengaluru Is No Longer the City Topping the Worst Traffic Congestion makes me happy and gives me strength :P
 
Haha, i mean, i stopped contributing to Bengaluru traffic too, so there's that ;)
 
2:32 PM
Yup we did :)
 
2:44 PM
Anyone know about flask.request.args.get('next'). What url we going to get
 
2:57 PM
hey guys anybody worked with flask_mongoengine? I am trying to implement the % filter similarly to sql with this dpaste.com/GMGUJ37L4 where i thought the '/.*' would work as the '%' but doesnt seem to function as such
 
 
2 hours later…
5:09 PM
Does someone know a deprecation library that can e.g. deprecate keys in a dictionary? I've only found some that tag functions and classes.
 
I've only seen that kind of thing implemented manually
 
@MisterMiyagi do you mean "deleting" when saying deprecating keys?
 
e.g. deprecating an attribute via @property or deprecating a kwarg by manually checking.
 
@alkasm oh, gotcha
 
You don't need a library to delete keys out of a dict, so I don't think that's the question
The oft-neglected del keyword will do
 
5:12 PM
@Kevin yeah, i just thought of the actual possible meaning of "deprecating", though deleting is a bit of a stretch
 
Hmm true, deprecation is sort of a very slow deletion
 
i learned semi-recently that deprecate is actually a much stronger verb than I thought it was. In English it generally means "express disapproval of" with synonyms like "deplore"
ofc technically we don't mean it that way exactly, but interesting nonetheless
 
I thought it was an alternate spelling of "depreciate" for quite a long time, because I had never heard it in any context other than software
 
Nope. From wiki: It derives from the Latin verb deprecare, meaning "to ward off (a disaster) by prayer"
 
In other words, if you thought anything at all about "deprecate", you were ahead of me
 
5:18 PM
@alkasm Yeah, I have a rough idea how to do it myself.
 
@Kevin I mean, might be another stretch, but you could also think that whatever is being deprecated is also depreciated (technically)
 
(I also thought the words were related previously, but they have different roots entirely)
 
It's just one of these things that is three steps away from the actual task, so was hoping to avoid "let's write another deprecation library". :/
 
sure, I just meant to say those are the only ways I've ever seen it done.
 
Can someone help me with the following recursion. I am trying to return a list of outputs from this hailstone_step function until it hits 0. The following function just yields the correct outputs but instead of one list I have several nested lists.
def hailstone_sequence2(a):

if a == 1:
    return a
else:
    #Update the value
    next_step = hailstone_step(a)

    return [a,hailstone_sequence2(next_step)]
 
5:21 PM
When I thought they were the same thing, it seemed odd to me to say that some code was depreciated. Because the only meaning of "depreciated" I knew was the economic sense where a resource gradually reduces in value until it's worthless. Code doesn't gradually becomes worthless, it goes from "works" to "works, but try not to use it any more" to "doesn't work". That's a three-step piecewise function right there.
I believe there's a second meaning of depreciate that's more abrupt, which is a better fit
 
yea but the -prec- part is related to "price" from Latin, so the cost is definitely inherent in the word
 
yeah. one of the possible meaning that could be used generally instead of economically would be "to lessen the price or value of."
Here if we look only at the word "value" this definition could work for anything generally.
 
@Govind75 you return a list, and one of the values in your list is a return value from your function. so you're gonna get nested lists.
 
Informative, thanks. I do love to collect latin root words
I keep them in a mental box in my mental attic, next to my mental box of cool rocks I have seen
 
@alkasm Yeah, I realised - I just can't think of a way to resolve it.
 
5:26 PM
I think you want to append to the list/extend the list rather than put it inside the list. an easy way you can do this is to "unpack" the resulting list, like return [a, *hailstone_sequence2(next_step)]
make sure your base case also returns the same type, in that case (e.g. [a])
 
Perhaps one could argue that the "works, but try not to use it anymore" is not a flat line in the "value over time" graph, but rather a smooth downward slope. Code that will stop working in a year is more valuable than code that will stop working tomorrow.
 
generally for recursive functions the base case and recursive steps should both be returning the same type---here they're returning a value and a list respectively, so that's a quick way to see it's wrong. Personally I'd use a generator here, though!
 
For developers that scramble to fix their deprecated code the night before its EOL, the slope may resemble a cliff that they're plummeting off of
 
@Kevin lol
 
@alkasm In our lectures we haven't explicitly learned to use *, I think they want me to use some sort of appending method, I tried it but I can't make it work without making the function accept two arguments
 
5:32 PM
@Govind75 why do you need two arguments?
 
If they're flexible about the order of the output, here's an append-based approach that gives you the answer backwards:
def hailstone_sequence2(a):
    if a == 1:
        return [a]
    else:
        #Update the value
        next_step = hailstone_step(a)
        seq = hailstone_sequence2(next_step)
        seq.append(a)
        return seq
 
damnit kevin
 
You can get a frontwards answer if you're willing to use addition instead of append. But this is quite expensive memory wise
def hailstone_sequence2(a):
    if a == 1:
        return [a]
    else:
        #Update the value
        next_step = hailstone_step(a)
        return [a] + hailstone_sequence2(next_step)
 
also wait, what? i don't think that's right
 
ah, I was * * this close
Im so bad at recursion :{
;(
wait
how can I append to an integer value?
 
5:36 PM
you can only append to a list
 
you can't
 
@Kevin it's the same as the unpacking variant.
 
Yeah, it is
 
i meant it as a rhetorical question -_-
 
Oh I guess I should point out that I changed return a in the original code to return [a] because I think it doesn't make sense for the function to sometimes return an int and sometimes return a list
 
5:37 PM
ah I see
 
Where possible, every code path in a function should return the same type
Regarding a two argument solution, I wonder if this is like what you had in mind:
def hailstone_sequence2(a, result=None): #do not do `result=[]` here
    if result == None:
        result = []
    result.append(a)
    if a != 1:
        hailstone_sequence2(hailstone_step(a), result)
    return result
This is more memory efficient than unpacking or addition since it only creates a single list object, rather than making a new one with every inner call
 
Yeah, kinda similar I guess
 
It's a bit of a janky approach IMO because it's kind of odd to mutate a list that's given as an argument, and return a reference to that list
 
I'm guessing a generator would be pretty memory efficient here, without adding mutation.
 
Yeah a generator would work
def hailstone(a):
    yield a
    if a > 1:
        yield from hailstone(step(a))
It's even easier if recursion isn't required
 
5:47 PM
def hailstone(a):
     yield a
     for a in iter(lambda: step(a), 1):
        yield a
 
Oof, I must be rusty, writing if result == None: instead of if result is None: like that
 
If you want less exposed to the user in your two arg variation you could also use a closure.
@MisterMiyagi the good ol' sentinel
 
@Kevin too much time in other languages :P
 
There's a design that uses while a > 1 instead of for but it's not as fun because it doesn't use neat functional paradigms
 
@alkasm I'm too old to start using asspressions!
 
5:51 PM
i bet you use emacs, too!
 
Whoa numpy has typing now???? numpy.org/devdocs/reference/typing.html
quite limited, dtypes and dimensions still unsupported it looks like.
 
6:15 PM
@AndrasDeak no
 
7:03 PM
cbg
 
7:27 PM
@alkasm Interesting root, given that money is "pecunia", without the "r". It's reminded me of one of the few times Latin has helped me understand a word I'd not encountered before - "impecuniosity"
 
@roganjosh "pretrium" -> "price"
(fwiw this is just from google searches, i don't know any latin)
 
Oh, I had 4 years of it :/
As you can see, it's totally stuck :P
 
@roganjosh I think a bit of a primer on greek/latin/arabic roots should be part of the curriculum for native English speakers. You could throw French in there too, but then you should probably throw Norse/Germanic and then it gets a bit more complicated, although faschinating.
 
@roganjosh i guess it means being broke?
 
Indeed it does :)
 
7:31 PM
cbg btw
 
@roganjosh I grew up in a state with poor education in the US, and went to public school, so I definitely had no such classes lol
 
cbg :) And Latin was ok-ish, and I guess it gives me some vague hope of understanding romantic languages without having really learned any of them. I get the odd word just from some memory I definitely couldn't actively call upon
 
regardless of the state I don't think greek/latin is particularly common at public schools in the US. most private school kids I know did take greek or latin for a few years, though.
 
I went to a private school, so it's basically one of those things you have to have under your belt to impress mummy and daddy's influential friends
 
I will unashamedly blame my mum for detailing a bunch of roots to me when I was very small. I don't really remember anything concrete, except vague memories of xyz means abc therefore you can figure out that xde means ...
 
7:40 PM
blatant dupe. Friends, Romans, countrymen, lend me your hammers. stackoverflow.com/questions/65832397/…
 
@smci Why not have 3882 answers with some of the more "fun" loopy solutions? :P Closed
 
@Govind75 "Hailstone sequence" is also far better known as "Collatz sequence", you'll find tons more code with that term. See Collatz conjecture.
@roganjosh I "conjecture" that the length of duplicate loops will grow unbounded... :S
 
It's quite remarkable to see some of the stuff that comes out of people not understanding pandas at all. That particular user has been on SO for 6 years.... I wonder how much of their day-to-day life involves "why does everyone keep saying that pandas is the go-to for data processing?"
 
@alkasm work in progress
> Annotations for NumPy functions. This work is ongoing and
improvements can be expected pending feedback from users.
Assuming that's the same thing. I don't do typing.
 
@roganjosh pandas is now the go-to for data processing (like SQL is/was), in the bad lazy sense that for any question, you can now google and copy-paste solutions from tutorials, blogs, bootcamps etc., and we see the influx from this on SO every day now. You can go for years writing inefficient code, or not reading the tutorials, or not thinking about non-scaleability. In fairness the pandas doc is only a skimpy syntax reference not proper user guide.
 
7:54 PM
is what i am attempting to do here dpaste.com/GZTHSLUB3 possible without getting this dpaste.com/FQGUKU3NT essentially the idea is to create a custom search using 5 inputs sent from react to flask and processed with mongoengine within this route dpaste.com/FQFT4R8ZN ... I have the query running nicely, however when the input field is empy the query calls and due to input returns all the documents, thus thought to use ternary operator to set to none if field is empty but
getting the error stated above
 
@AndrasDeak yep! yeah, that is the same thing.
 
@Kwsswart I think you need to decouple this from at least Flask, if not also Mongo. Why is 'surname' : re.compile('.*' + req['surname'] + '.*', re.IGNORECASE if req['surname'] else None), trying to make an int type?
I don't know regex but that seems particularly odd
 
00:00 - 20:0020:00 - 00:00

« first day (3750 days earlier)      last day (1181 days later) »