« first day (3789 days earlier)      last day (1142 days later) » 

user13727121
3:18 AM
Should I adhere to a single return statement per function or multiple return statements for the sake of clarity? Example: dpaste.com/3D6D5RHNX
 
3:53 AM
actually you dont need an if else there at all
if start is greater than 100 then the list() for that range will return [] @CoreVisional
sorry, I ran that and what I said is wrong, ignore that
 
 
4 hours later…
7:40 AM
@CoreVisional you don't need the else because if the if is True, then it returns and execution flow leaves that function. it's common to write that as:
def every_three_nums(start):
    if start > 100:
        return []
    return list(range(start, 101, 3))
and the end should be 101. otherwise it will output 102 as well - which I think you don't want
and as a one liner:
def every_three_nums(start):
    return [] if start > 100 else list(range(start, 101, 3))
and since range() will not include the upper limit, this this will do:
def every_three_nums(start):
    return list(range(start, 101, 3))
 
@aneroid this was what I meant but I didnt realize they had 103 instead of 101
 
every_three_nums(93) --> [93, 96, 99]; every_three_nums(100) --> [100] and every_three_nums(101) --> []
@python_user yeah, i think what you meant was correct ;-)
...not that they are in chat now. does it send a notification?
 
yeah they get it on the main page, but even if it diditn I have seen them hopping here the past couple days so its ok to assume they will be back
 
@python_user ah, ok. i get the notification too but I don't know if it's coz the tab is open or it notifies anyway. thx
now, I wonder - does @CoreVisional want "every 3 numbers" or "every multiple of 3" from start to 100 (99) ?
 
I dont how those browser notifications work, I meant the ones that show in SO "Recent Inbox"
 
8:21 AM
@python_user yeah, i meant that too - the inbox
 
9:04 AM
hi everyone.

I'm researching a sync solution for a project that is meant to be used in an unstable internet connection environment.

Yet, things must be done at least locally then be synced later with the live version of it.

The app is meant to be used by volunteer medical staff for example, if the internet is not available the process shall be made locally until the internet connection is back on their computers.

is there is any python package or tutorials that might help ?
 
What are you syncing when there's no internet connection?
 
Database basically, any changes to the database should be reflected to the other parties oversea
I was thinking about storing all db requests on a file and then by the next syncing request it should just update the online version line by line. but I'm not sure if that is the best idea.
 
That's... difficult at best. What happens if two people make changes that conflict with each other?
 
Are you aware that certain flavours of databases already do that for you? Most importantly, they will ask you the nasty questions – like conflict resolution – you need to have an answer to.
 
oh, the other parties using the online version won't be making any changes to the database, but they should be able to read them.
 
9:12 AM
So what you are looking for is eventual consistency?
 
@MisterMiyagi I didn't know that, I haven't done it before either so I'm not sure what I should be looking for.
@MisterMiyagi local staff/team be able to do about all what they need to do without caring about the internet issues, while keeping the overseas parties updated asap
 
If you haven't already, read up on the CAP theorem.
That's the high-level few on what can and cannot be done with such a use-case.
Ideally, you should read up on what features you need (e.g. "eventual consistency", "sharding", ...) and then just hit google to find whatever tech gives you that out of the box.
 
how about that :

local : request changes.
local host : check if request is accepted
local host : if accepted > apply changes locally and store them (somewhere ) then add it to the syncing queue.
local host : once being sent and the other server confirm the changes , delete it the request from the queue.
 
That's really not possible to answer in general. It might work, or it might not – it really depends on your requirements.
For example, in this usage model it's important how the system reacts to partial or unacknowledged updates.
 
just updating the online database, the online version won't ask questions, It just needs to be informed.
 
9:27 AM
So you are fine with, say, applying the same update twice?
Is data read-only, or can it be changed?
 
you mean like once locally and one online ? yes that is the goal.
i haven't created the database yet, we are in the brainstorming stage.
 
@LoopingDev No, like once online and then again online. Because an acknowledgement did not get recorded.
 
@MisterMiyagi yeah , as long as it gets updated and both databases are identical, that is fine.
I guess I will need to relay on some sort of Async methods to confirm that the data are updated before removing the request from the queue.
 
That's like saying you should drive a diesel car to make sure you don't miss any luggage.
If your updates are unique (later ones do not subsume earlier ones) then you must make sure they have been applied. Whether you do that sync or async does not change that.
 
I see, I guess all changes regardless of it's type must go through queue.
so i'll probably have to make a function that manages all the changes.
 
9:42 AM
Why are you making it sound like you're planning to implement this yourself after MisterMiyagi told you that databases with this feature built in already exist?
 
@Aran-Fey Oh I totally forgot about that, could you tell me the name of that feature to look it up and see how it handles things ?
 
Generally, you are looking for "replication". What flavour of replication you need depends on your use-case.
 
@MisterMiyagi thanks a lot, I will look it up, and I guess we will find out
looks like it's master-slave replication is what I'm looking for , the overseas parties would be reading from the "slave" server.
For my project I'm using flask_sqlAlchemy, but I haven't done that before.
has anyone ever tried "flask-replicated 1.4"(https://pypi.org/project/flask-replicated/) ?
I'm concerned about how it handles the connection dropping.
 
10:09 AM
It won't handle the connection dropping, it will timeout. You'd need something like APScheduler looping and pushing updates. Your task does not lend itself to a webapp
Actually, even that won't work because the change would be local. FWIW this is why I started looking into kotlin because I couldn't find a clean solution in python for this
 
user13727121
@aneroid It is up to 100 in increments of 3. Your answer is correct, the REPL also evaluated my answer as correct, but I prefer that single return statement. However, my original question is whether or not should I stick to a single return statement or multiple return statement.
 
10:50 AM
well my plan was after I set everything up as a webapp, later, I would convert it into an excitable version for the local users and add whatever pushy functionality method there is and store the queued requests somewhere and just read them one by one by the next sync request.
 
Erm... I think you've just added authentication and authorization to your requirements list.
 
i think it has been there long ago lol, every user could only request update to him/herself only either locally or online
 
If you just have some executable that users can just execute as they feel like, you have to be prepared with a) someone else executing it and b) the user executing it unintentionally maliciously.
 
i dont want make things too complicated, it's a charity org program, so I highly doubt that any of them would sink that low.
but if i want to make things way complicated i could add google auth on each update lol
 
Security by faith in humanity? That's a new one
 
10:57 AM
that is old one ^^ , but they really have very little knowledge about tech in general, and i mean by little none , nada lol
 
Well, if it's medical data as you implied, there likely is a lot of fine print about who may access (both r/w) it. Just trusting the staff is very, very likely not sufficient.
FWIW, the users with the least technical knowledge give me the most headache. They thend to be... creative in using software.
 
oh, I wont trust anyone at all, I will just have light security at first like (( tokens , ssl .. etc)) and increase it if needed later, but I highly doubt that we would.
@MisterMiyagi lol
 
@MisterMiyagi also phishing
Although that's harder to fix with security
 
No passwords = no phishing. Easy
 
@AndrasDeak 2-factor auth with hardware tokens. D:
 
11:06 AM
yeah people with the least knowledge gave me headache but not just in head lol.
but I think it would be fair to use standard security at first and expand as needed.

if you don't know charities are quite busy during these times, so they might be doing lots for requests to keep it up.
too much security would impact the work flow i believe
 
@MisterMiyagi they can still be called from IT and asked for the code
 
@LoopingDev Just make sure that too little security does not impact you. Depending on the jurisdiction, you better be safe than sorry.
 
@MisterMiyagi I'll keep that in mind. but I'm not getting paid for this so I think I would be alright either way lol.
 
@AndrasDeak "This is Paul calling from IT, trying to check whether you can register new hardware tokens."
 
my only concert is what we have been talking about it since the beginning is that I dont want to end up with 2 databases that are out of sync, and also to protect the online database from any corruption / issues that might occur locally (ex: deleting some records by mistake ) , It would be better to manage what data gets synced and what not to avoid corrupting both databases.
Also if high pathetically a malicious software starting corrupting it, Managing what gets sent on the online server would be better handled manually.
 
11:39 AM
@LoopingDev I'm not a lawyer but "I risked patient's sensitive data for free" doesn't sound like an excellent defense
 
Hi everyone I need some help regarding a date related dilemma. So it happens that I have data for week 53 of the year 2020 and am creating a column called 'cohort' based on the combination of the week and year. However I am running across a challenge which I have highlighted in this MCVE: pastebin.com/7DRxHAiY
 
well that is why I'm going to add standard security there.
I don't think I have to do more than that.
they just have to be careful with the patient data they have.
 
I don't think "I don't think" is enough when treating sensitive patient data :P But as others have said there are insane differences between local jurisdictions in this regard.
 
yeah, I'm aware of that, as far as i know they don't have high data restrictions in the regions where the org operates.
 
11:53 AM
I think this will help, thanks s lot! @Aran-Fey
@roganjosh I was able to debug my cron job thanks to the links you shared yesterday!
 
Glad it helped :)
 
12:15 PM
@CoreVisional and wrt that, this was my reply: chat.stackoverflow.com/transcript/message/51689489#51689489
@RaphX I recently had this in one of my time series. the solution is a bit more straightforward - use isocalendar for both year and week. otherwise, you get it as 2021 week 53 (which hasn't happened yet, ofc)
stats.insert(1, 'Report Year', stats['Report Date'].dt.isocalendar().year)
stats.insert(2, 'Report Week', stats['Report Date'].dt.isocalendar().week)
dt.week is deprecated anyway. dt.year is still available but not suitable for what you want. .dt.isocalendar().year will align with dt.isocalendar().week
@RaphX so in your case:
test_dataframe['year'] = test_dataframe['date'].dt.isocalendar().year
test_dataframe['week'] = test_dataframe['date'].dt.isocalendar().week
 
12:54 PM
thanks a lot!@aneroid
 
user13727121
1:13 PM
function definition must be in order, right? I'm so lost right now trying to split my code into functions... This is a functional program with a terrible coding style: dpaste.com/GN8TTWG2R, and this is what I was only able to come up with until my brain stops functioning...: dpaste.com/6ER3KEGWW
 
function definitions can be in any order you want
 
The only restriction is that a function must be defined before it is called.
 
user13727121
@Aran-Fey all I gotta do is to reference them, right?
 
Remember that function/class definitions are executable statements, not declarations, in Python.
 
user13727121
I'm a little confused...for example, how do I call upper_bound from generate_random_number, because random_num will ask the user to input an upper bound again instead of taking the number the program first ask them to input
 
1:25 PM
You should call set_upper_bound, store the result, and then pass the result to generate_random_number.
 
the name "upper_bound" doesn't really matter. as long as generate_random_number is being passed the value, theres where it will take it from
this is a shift in thought process from "oh my entire program attaches a meaning to this variable" vs "this variable only has a name and meaning inside this function, i should pass it around as needed"
Quick question, came across this behaviour today
def __badname(foo):
    print(foo)


class Hi:
    def yo(self):
        __badname(42)

Hi().yo()
 
name mangling
 
turns out apparently even this gets name mangled. so, if someone external to me wrote a name with double underscores, and i needed to write a test for it, what should i do?
 
You can access globals["__badname"]
 
(with the context that pytest likes tests in classes as methods)
oh.
a sin to fix a sin? i see
ok perfect, thanks Miyagi
 
1:30 PM
Obligatory advice: just rename the thing. :P
 
haha yeah, i dont wanna touch that part of the code, it's apparently "off limits"
every single function in this file starts with double underscores. :/
 
@ParitoshSingh Probably because weird things happen, eh? ^^
 
haha, quite possibly!
but yeah, i will admit i was rather proud of myself for remembering name mangling and connecting the dots. although this does surprise me, why did it get name mangled in the first place?
 
user13727121
@MisterMiyagi So I call it outside the function definition set_upper_bound, and then result = set_upper_bound, and then pass that into random_num?
 
result = set_upper_bound() but yep, you got it
(ie. call the function)
 
1:34 PM
hey quick technical question.

I use VS as an editor for C# and it's superb at reminding me the classes, options , parameters ...etc

is there is any similar package for python ?
so far I've tried Atom and VS but they seem to be lacking something, did I forget to install some python packages or is there is a better editor for python ?
 
re name mangling i had gotten the impression that it would only mangle methods of the class and so on
and not necessarily a random function just being called
i believe VSCode with the python plugin can do that too, so im curious what exactly it does for C# that makes you feel it's lacking. there's pycharm that's a full fledged IDE that some people prefer, perhaps that will do the trick?
(full disclaimer, i dont use pycharm)
 
user13727121
@ParitoshSingh It produced a TypeError when I put the result in random_num = random.randint(1, result) and print it out to test it
 
if u click on a variable or a class it navigates you to the class
also if u are writing a function with parameter it gives hint of all the available options to it, so you could scroll between them and chose which one you need.

It's very helpful , also the spelling mistakes , if u wrote down a variable that hasn't been defined it highlight it for you.

it's just way more engaging.
its the same software so I'll try the python plugin for VS , thanks for the tip :)
 
yeah all this should exist
yep, make sure you have the plugin
 
I'm glad to know that.
I thought that was the only available way to code in python.
 
1:47 PM
morning cabbages, folks
 
@CoreVisional can you show us the code?
 
user13727121
@ParitoshSingh sure, dpaste.com/7SDQW5XDB
 
oh. you removed the param. i assume this code runs right now
 
user13727121
@ParitoshSingh No, it gives a TypeError
 
but it would be better if you kept def generate_random_number(result): and then explicitly "passed" it the value in line 18 generate_random_number(result)
oh
whats the error?
i have to run though. bbl
 
user13727121
2:02 PM
@ParitoshSingh TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'. That means when I called generate_random_number, result will be the argument, right
 
yes. and ah right, your while loop has a break, and the return is indented
so the return line never gets run.
unindent the return upper_bound line
 
@CoreVisional replace break with return upper_bound
As already mentioned, it would be much better to pass the upper-bound to the generate_random_number function as an argument rather than having it rely on a global ("explicit is better than implicit").
 
Why do we have compiled code in our git repo not just source code? Answer: because it's part of our software. What kind of answer is that....
 
The kind a person who doesn't understand software development very well might give?
 
user13727121
@holdenweb that works... Thank you. Also, how does calling and storing the returned result in a variable works the opposite than just do it like random_num = random.randint(1, set_upper_bound())? The variable calls the function too without asking for user input again, but the latter ask for user input only
 
2:14 PM
Deliverables should be reliably producible from the sources.
@CoreVisional Correct. Every time you call the set_upper_bound function it will ask for NEW upper bound. If you want to use the same upper bound for multiple runs then save the result of set_upper_bound (which should perhaps be renamed get_number?) and re-use it for each call.
 
user13727121
@holdenweb I supposed the code should be like this? def generate_random_number(upper_bound): or should I just move the entire code under set_upper_bound to generate_random_number instead
 
user13727121
@holdenweb Owhhh I get it now, when the user input a number, that number gets saved to result, and then random_num takes that number in
 
I'd leave it as a separate function: you might find you want to use a different strategy for setting the upper bound later, so encapsulation in a function makes sense.
@CoreVisional Kaching!!
 
@DataTao Please take a look at the room rules. In specific, we ask not to advertise new questions (<48h) here.
 
it also doesn't hurt to say "hi"
 
user13727121
2:29 PM
@holdenweb what happened to pass upper_bound to generate_random_number? result's a global variable right
 
@holdenweb our senior/lead software engineer...
 
wow
Is it at least in git-lfs?
 
no
 
It lives in the module's namespace, yes, but if you make it a parameter then the value is determined by the argument you provide when you call it: a function call's local namespace is initially populated only by the call parameters, whose values are the arguments to the call. So the function doesn't know (or care) that result is global.
 
tbf it's python protobuf generated files, so not exe or some other compiled format, but still it doesn't belong there and is annoying to have the diffs in pycharm. Makes me miss what really changed and what stayed the same
Then again our workflow for installing a new system is clonezilla instead of a reliable build script
 
2:34 PM
OK, maybe introduce him to artifactory or another of the artefact stores. There's a place for that sort of thing, but IMHO it isn't in the source repository,
 
@Hakaishin I'm sure nobody will notice if you git rm them and change .gitignore :P
the great thing is that having cruft like that in git means everyone just runs git add . every time to pick those all up
 
I'm thinking about it ;)
this guy can be reasoned with, but it's kinda mood dependent I think. So I will wait for another day, maybe when he is in the office, that's also always better than over chat and talk about it again
 
good luck
 
@holdenweb interesting. looks cool, gotta look more into it
 
make sure to concentrate on the technical matter and reasons and not how he's all wrong
 
2:39 PM
ofc, I was already looking for reasons, but the first thing I found was, just dont do it. But yeah visual clutter is a good reason I think, size is not such a problem in this case since they are just python files. Any other reasons?
jfrog looks so neat. Great website and marketing dep. But I always find the argument funny, chose us to prevent vendor lock in. But you are simply trading a lower level of vendor lock in to a higher level. Ofc this might be worth it sometimes, but by itself that statement is pure marketing fluff and says nothing :D
 
3:15 PM
ugh, our config is getting saved in the db as 1 long string.
 
3:43 PM
cbg \o
 
3:57 PM
@piRSquared cbg - been a while!
 
ai it has
 
4:17 PM
cbg!
 
Guys, please can you look into this question that I've asked: stackoverflow.com/questions/66425663/…
The question is around ReactJS, Python Flask and axios.
 
Hi @ShridharK, room rules ask you to wait 48 hours after asking a question on the main site before asking here.
 
sorry, I didn't know that. Thanks for letting me know :)
 
np (-:
 
4:46 PM
cbg!
 
5:36 PM
Question eddited: May needs review stackoverflow.com/questions/66410822/…
 
@ChrisP Is there a reason for the several, huge code-blocks-in-strings?
Scratch that: Is there a reason for the huuuge code block and apparent lack of a focused, practical question?
 
6:02 PM
hi , which is better in handling notifications drop down similar to the ones we see on social media like facebook ( flask-flash ) or ( SocketIO ) or something else?
 
and again, I find myself realizing that I have no idea what async/await is. Could someone help disambiguate? Specifically: is there ever a time when an await'd expression does not block the running thread?
 
6:18 PM
well , i guess I could answer part of my question,
notification with socketIO sounds like a special room that is created between user and the server only ( so basically an empty room )
then the server pulls all notifications' data from the database and feed it to the notification drop down ? ...

The room is established when the user login and destroyed once the user leaves

i dont know if that is the right way to do it.
 
6:30 PM
@MisterMiyagi I will update the code.
Keep there.
 
@inspectorG4dget Depends on what you mean when you say "block". It'll block execution in the sense that the function won't resume until the thing you're awaiting completes. But the thread isn't exactly "blocked", the thread just goes on to work on something else
 
@Aran-Fey no. I'm trying to guarantee that the thing I await will finish its sideeffects before the next line of code is executed. This, I'm told, is incorrect and I need to call loop.run_until_complete in some really weird way, which I want to avoid very badly
 
@ChrisP It seems to me, if you don't mind me saying so. that you may have undertaken to solve a problem beyond the scope of your current abilities. While this is a good way to learn it taxes the knowledgable answerer since it's hard to know exactly how far to backtrack to start from solid ground.
 
That sounds incorrect to me, but maybe I'm missing some context. If you have something like await foo(); print('bar'), then the print will only run after foo has returned. Unless foo goes out of its way to circumvent this of course, for example by starting another thread, or by queueing a background task with loop.create_task
 
@Aran-Fey see, that's exactly what I'm trying to get at. But each person I talk to says something different
 
6:42 PM
@Aran-Fey To clarify, it's guaranteed that foo will return before the print is executed. But foo can indirectly do additional stuff after it's already returned with the help of a thread or background task or whatever
 
class Foo:
    ...
    async def some_func(self, stuff):
        # weird state change stuff
        result = await weird_func(stuff)  # this thing writes to a DB, don't think that's relevant though
        # rollback state changes
        # continue with unchanged state
 
I read (skimmed) the question. "So, what can i do with PyAV quality, and how can i impove [sic] the rest class (avoid timestamp=None error)?" seems like an unsatisfactory conclusion to an over-long question, which highlights the imperfect nature of your current understanding.
 
my fear is that await weird_func(stuff) will not finish until after I continue
 
6:46 PM
@inspectorG4dget I'm 99% sure that you don't need to worry. But since I've never really done any proper async stuff, I'm not confident enough to go with a full 100%
 
@Aran-Fey much thanks. It's good to get some confirmation validation
 
Or, to put it another way: If I'm wrong about this, then everything I thought I knew about asyncio is wrong
 
7:02 PM
Hi Everyone
 
well, technically weird_func could spawn a new task... :P
 
anyone here please??
I need your help in Python programming
 
@MisterMiyagi already mentioned that :P
 
I've found that the only way to be 100% sure is to use run_until_complete, to ensure that it is a blocking call.
But then, you need to pass in the loop to every function.
Not ideal.
But then again, I know very little about async, and find it confusing.
 
@inspectorG4dget await is an expression, and like every expression is has to run until completion before an "outer" one, let alone the next statement, can run.
@Aran-Fey I blame concurrency D:
 
7:07 PM
@MisterMiyagi sure. So the coroutine is awaited before the next line executes. But does that necessarily mean that the coroutine finishes its execution? This probably seems like I'm picking at nits, but I really don't get this - asking out of genuine curiosity
 
@inspectorG4dget Yes, a coroutine will finish completely when it is await'ed.
 
so you don't need to explicitly do a loop.run_until_complete?
 
This is exactly the same as a generator will finish completely when yield from'ed... yield from'd... yield from'st. used with yield from.
 
def mergesort(mylist,key=lambda x:(x,x)):
if len(mylist) > 2:
mid = len(mylist) // 2
left = mylist[:mid]
right = mylist[mid:]

mergesort(left)
mergesort(right)
i = 0
j = 0
k = 0
while i < len(left) and j < len(right):
if key(left[i]) > key(right[j]):
mylist[k] = left[i]
i = i + 1
else:
mylist[k] = right[j]
j = j + 1
k = k + 1
while i < len(left):
mylist[k] = left[i]
i = i + 1
k = k + 1
while j < len(right):
mylist[k] = right[j]
j = j + 1
k = k + 1


list = [['Binsy','CategoryA', 97],
['Atheresa','CategoryA', 94],
 
@Mina highlight everything and ctrl-k
 
7:10 PM
I want to sort my list using merge sort algorithm, by category and marks
 
@MisterMiyagi thank you very much. This really helps. One other question: I'm aware that async/await has gone through a lot of changes over many python versions. Are you able to clarify which python version this is accurate as of?
 
def mergesort(mylist,key=lambda x:(x,x)):
    if len(mylist) > 2:
        mid = len(mylist) // 2
        left = mylist[:mid]
        right = mylist[mid:]

        mergesort(left)
        mergesort(right)
        i = 0
        j = 0
        k = 0
        while i < len(left) and j < len(right):
            if key(left[i]) > key(right[j]):
                mylist[k] = left[i]
                i = i + 1
            else:
                mylist[k] = right[j]
                j = j + 1
            k = k + 1
 
@inspectorG4dget The behaviour of await/coroutines hasn't changed significantly since 3.6.
 
@MisterMiyagi much thanks
I sir, owe you a fully sanded deck... or a painted fence
 
My output must be like this: ['Binsy', 'CategoryA', 97],
['Atheresa', 'CategoryA', 94]
['Amena', 'CategoryA', 60]
['Silpa', 'CategoryB', 96]
['Muzhgan', 'CategoryB', 78]
['Preety', 'CategoryC', 98]
['Raju', 'CategoryD', 22]
 
7:12 PM
@GamesBrainiac The loop.run_until_complete is done by sync code to run async code. These days one should use asyncio.run instead.
 
@Mina key=lambda x:(x[1],x[2]) or key=operator.itemgetter(1,2)
 
@inspectorG4dget I used lambda function but did not worrk
 
@Mina Umm, why should 'CategoryA', 97 appear before 'CategoryA', 94?
 
> I used lambda function
please show us what you did
> it did not worrk
please show the traceback
 
@Aran-Fey Because I want to sort by Category and inside each category I want to sort by marks.
 
7:16 PM
Then you need to sort by (x[1], -x[2])
 
Air
Descending. The word you accidentally is "descending"
 
In categoryA first sort all student's marks then CategoryB ...
@inspectorG4dget how should I pass the key when calling the mergesort function?
 
@Mina merge_sort(my_list, lambda x: (x[1], -x[2])
 
Air
)
that'll be $5
 
@inspectorG4dget in function call, right??
mergesort(list,key=lambda x:(x[1],-x[2]))
print(list)
 
Air
7:25 PM
Why not try it out
 
what happened when you tried that?
Kevin'd by @Air
 
the output is : [['Preety', 'CategoryC', 98], ['Raju', 'CategoryD', 22], ['Amena', 'CategoryA', 60], ['Muzhgan', 'CategoryB', 78], ['Binsy', 'CategoryA', 97], ['Atheresa', 'CategoryA', 94], ['Silpa', 'CategoryB', 96]]
do not sort,
 
This might suggest that the code is buggy
left = mylist[:mid]
right = mylist[mid:]
those are (partial) copies of the input list ^
 
that's because your mergesort function recursively splits the input (as it's supposed to), but does nothing when the size of the list is <=2. You correctly have if len(mylist) > 2:. What happens in the else condition?
 
Air
This isn't an answer to your problem but ditching i, j, k for more meaningful variable names could help you debug more effectively
(Or not, but it wouldn't hurt)
 
7:29 PM
Considering how much difficulty we had just passing in the key function, I don't see much hope for successfully debugging a merge sort...
 
Air
Hope yields eternal
 
@inspectorG4dget it just check in the first that the list is empty or not
 
@Mina at this point it seems there are quite a few issues with your code and it doesn't sound like it would be easy for us to help you with all of it. You might benefit from learning how to use a debugger at this point and step through your code, comparing what it does for a small example with a paper-based solution. It might still not be enough: debugging recursive code is difficult.
 
@AndrasDeak ohh, to ignore my code, how can I sort this list using merge sort algorithm , any other solution ??
my desired output is like this: My output must be like this: ['Binsy', 'CategoryA', 97],
['Atheresa', 'CategoryA', 94]
['Amena', 'CategoryA', 60]
['Silpa', 'CategoryB', 96]
['Muzhgan', 'CategoryB', 78]
['Preety', 'CategoryC', 98]
['Raju', 'CategoryD', 22]
 
@Mina well, do you have to write merge sort by hand?
 
7:33 PM
Do you have to use a merge sort?
 
@AndrasDeak yes, but just working with one dimensional array like [1,5,3,5,6,7]
@Aran-Fey yes
here is a list of list or array inside array , also need to sort by to columns . I do not know how to do
 
If you're stuck debugging that code, I'd try removing mutation from the picture so that the function returns a new list. Well, first I'd try asking for help from TAs or whatever.
@Mina it's almost the same thing, except instead of comparing "5" and "3" you're comparing 2-length tuples. Very small complication.
Perhaps you should first write a mergesort that sorts flat lists correctly.
 
Air
If you need a refresher on the merge sort algorithm you could do worse than this CS50x video
 
if you've written the one-dimensional merge-sort, I'd recommend starting from there, rather than starting from scratch
 
I might be missing something here... isn't sorting always one-dimensional?
 
7:37 PM
this is QuantumBogoSort
 
Yeah, it is. I suspect their "one-dimensional" sort simply doesn't accept a key function.
 
They didn't say they have a working version for flat lists, did they?
ambiguous at best
Most likely scenario: teacher gave code for the flat case, and they only have to make it use a key
 
I suspect they don't have a different algorithm for "one-dimensional data". Instead, I think, this very same algorithm just happened to work correctly with a list of numbers as input.
 
The above code can't work correctly
 
Depends on the input :P
 
7:40 PM
true, it probably works for any length-1 or empty list
 
Wait, it can't? I'll admit I didn't take a close look
 
@AndrasDeak it works with flat list when I pass one key x[0]
 
@Aran-Fey ah, no, I misread
I attributed more significance to the recursive part, I thought it was supposed to affect the original list
so it might work, I didn't take a closer look at the rest of the code
 
@Mina same course you're taking?
 
7:45 PM
but here is just by one key, and I want to sort by 2 key
@AndrasDeak yes
 
@Mina did you check if the exact code in that answer works for your problem?
 
@AndrasDeak No, it have problem. do not solved for its questioner also
 
@Mina I see. Because I'm pretty sure that if it works for x[0] as key then it will also work for (x[1], -x[2]) as key.
 
@AndrasDeak unfortunately do not work.
what should I do ?
 
Find a merge sort that works?
I've got to say though, I have no idea where the bug in that code is
Been staring at it for 15 minutes
 
7:58 PM
def mergesort(mylist):
    if len(mylist) > 1:
        mid = len(mylist) // 2
        left = mylist[:mid]
        right = mylist[mid:]

        mergesort(left)
        mergesort(right)
        i = 0
        j = 0
        k = 0
        while i < len(left) and j < len(right):
            if left[i] < right[j]:
                mylist[k] = left[i]
                i = i + 1
            else:
                mylist[k] = right[j]
                j = j + 1
            k = k + 1
        while i < len(left):
this works for just one dimension array
@Aran-Fey I paste the code
 
I meant the code from the answer on SO
 
@Aran-Fey No
 
Huh?
I'm saying I can't find the bug in this code
 
Can you code yourself?? ignore my code. use the data and sort by category and marks??
 
*facedesk* Never mind, I found it.
No, I'm not going to write or fix a merge sort for you, if that's what you're asking
 
8:05 PM
@Mina Your recursive call does not pass along the key function.
 
@Aran-Fey found the solution??
 
@MisterMiyagi How long did it take you to find that? :|
Be honest, I can take it
 
@Aran-Fey Cleaning up the code and removing the defaults along the way was helpful. ;)
 
@MisterMiyagi no answer again
 
I have no idea what "no answer" even means.
 
8:09 PM
"Hello, Darkness, my old friend"
 
it was answer to this, Your recursive call does not pass along the key function. I pass key to recursive function.
:51693954
 
@Mina Your code shown above does not.
 
mergesort(left) doesn't pass along the key.
 
@Aran-Fey could you find the problem of this question?? stackoverflow.com/questions/60508591/…
 
Yeah, I already have.
Already posted about it.
 
8:14 PM
@Aran-Fey can you share please
 
We clearly aren't making any progress here, so I'm gonna leave you to your own devices
 
@Aran-Fey just share the solution of that code
 
We already have. And that's the last thing I'm gonna say
 
@Aran-Fey it does not work
anyway, thank you
 
 
1 hour later…
9:29 PM
deep cut: "stop comparing yourself to other people and just try to do better than you did yesterday (or any period of time ago). Anyone ever feel like their past self would be ashamed of their right-now self?
 
Do you want the true answer or the encouraging one?
 
I suspect I'll hate the truth, but that's what I probably need right now
 
Ashamed for what? Being too good at coding? Because that's what that thing is meant to address.
@inspectorG4dget no
 
@inspectorG4dget Past self has a lot to answer for. Someone had to clean the kitchen, and it definitely wasn't current self!
 
sigh... it doesn't happen very often, but it's very humbling when I realize I haven't actually learned a lesson I thought I did
@MisterMiyagi rofl!
 
9:33 PM
if it was common for humans to monotonically increase in knowledge and wisdom the world would be a very different place
You have ups and downs. You just try to make it so that you're on a non-decreasing trend in the long run.
 
I need to frame that in a cross-stitch or something
 
10:02 PM
I just go with "Live. Laugh. Love.". I think that epitomises me tbh :P
When I'm not yelling out of the window at those hooligan kids for cycling on the lawn... or going about my daily business, for that matter... :P
 
10:27 PM
I call this animal debugging - when you have a rendered front-end that basically doesn't allow you to step-through debug, add a bunch of animal noises in your display text to see which part of the code generates that piece of the front end. Now you know where your problem is
 
10:45 PM
TIL of Windows Terminal. Has to be configured by manually editing a json file, but once it's set up, it's pretty slick. Goodbye ConEmu and Cmder
 

« first day (3789 days earlier)      last day (1142 days later) »