« first day (3269 days earlier)      last day (1678 days later) » 

1:41 AM
cbg
 
 
4 hours later…
6:07 AM
hello peoples
 
6:58 AM
hello
 
cabbage @ParitoshSingh
 
Hey, hows it going!
 
It is Rugby time!
 
oh nice!
i'll admit, not a sport i know a lot about
 
I spent my youth on the track and under the rucks!
 
7:14 AM
oh wow, that's pretty cool. Though, it's a pretty rough sport right?
did you accumulate any "Battle scars" so to speak? :P
 
...and now it seems like CCTV has cancelled the match to pass Chinese softball! ##%$&@@$
 
Yes, lot's of them... After my track and rugby years, I did full contact karate, and I still do!
Dang'it, I specially paid a month sub to CCTV, and upgrade the equipment, just for the Rugby WC... Now they are not airing the matches!
 
aww, that's really rough
where are they being aired then?
perhaps you can find an online stream for it instead if that's an option
 
Oh well, I'll go watch the other match at the pub - they also have beer and burgers... it is Saturday after all!
 
7:20 AM
Mm, now i'd like to join as well :P
 
Sure, come along! :)
rbrb
 
rbrb as well
 
 
1 hour later…
8:51 AM
Should this be closed? User samples 1999 numbers from a list of length 1000. Also, the title needs surgery.
 
9:53 AM
hello ! I have a question guys
i have already learned enough python to make useful programs and am able to solve many problems in this language. I know No framework and have no idea where to start. should i first learn it really deeply by reading a 1500 page book like learning python and then move to learn the frame works or no this is enough to learn django ?
Q2 : should i learn SQL or mySQL and then jump into frameworks ?
Is anyone there ????
 
10:33 AM
@MohVahedi if anyone is there who can answer and wants to, you'll know
 
Hi all
I got a small question: why can't I do print(*os.walk(folder), sep = "\n") ?
 
@superkytoz define "can't do"
 
Because I can use os.walk() in a for loop, but now I just want to simply print the whole array.
@AndrasDeak can't print the return value (list_iterator) of os.walk()
 
Define "can't". Does your computer explode?
 
@AndrasDeak can't print the whole array inside a for loop.
need to be outside a for loop I discovered
my bad..
 
 
4 hours later…
2:55 PM
@MohVahedi how did you learn to make useful programs? take that "how", and just apply it to learning frameworks as well. Go for your tried-and-tested method of learning.
 
3:36 PM
@ParitoshSingh , thank you for reply.
 
np. for some people, it's books. for others it's projects. for some others, it's a mix of the two. find what suits you best
 
3:51 PM
cbg
 
4:20 PM
Hello!! Total newbie jargon question for anyone who's around: I want to execute a code based on an instruction/key, but I don't want to use a bunch of clunky if-else blocks. I vaguely remember there being something like a key, and you jump straight to that key and its associated code in C. Is there something like that in Python, and what is it called? (So that I may look it up properly! Right now Google is exasperated with me...)
 
A dictionary?
 
Nope.
This isn't a key in that sense, I'm not here to store values, but to execute codes.
Perhaps something like having a bunch of functions fn_*(), and if you input 'n', then you execute fn_n()
 
Nope. That's multi-level. There's a very very simple solution in C and I wish I could remember that jargon, so I could just ask what's analogous to this in Python
 
Doesn't help that I can't write C, so I guess I give up at this point in guessing
 
4:26 PM
Unless.... Can I have a dictionary like this {'1': fn_1(), '2': fn_2(), '3': fn_3()}, and have the values as functions? How would I call them? Is there an execute statement?
 
this is the use case of a dictionary
 
Amazing
 
dictionary['1']()
 
in python, everything is an object, including functions. so they can be stored as values
 
() is the execution. Store the functions in the dict but don't call them
 
4:27 PM
Then this is the equivalent I was looking for. How do I call them?
 
after you do the lookup, calling a function remains the same. as roganjosh said, just use the (args)
 
As Pichi suggested
 
so, some_dict[key](some_args)
 
Brilliant, okay!
Trying this out right now.
 
the main thing is making sure you dont call the function and store the return in the dict values, you store the function itself
 
4:29 PM
Gotcha.
It's working! Thank you so much both of you. I appreciate it
 
@user3625380 if you have indices 0,1,2... you can also use a list of functions
 
Oh? what would that look like
and in terms of computational cost would that be better?
 
It doesn't make a difference, really, in computational cost if you want to specifically access functions by index
[func_A, func_B, func_C] vs {0: func_A, 1: func_B, 2: func_C}
 
@user3625380 funs = [fun0, fun1, fun2]; res = funs[1](*args)
Of course it's more readable as fun = funs[1]; res = fun(*args)
But a list only works with contiguous integer indices from 0
 
yeah... dict-dispatch is generally better... not only can you name stuff, it also makes it easier to use a default without exception handling if needed (and just as easy to handle a KeyError vs an IndexError otherwise...)
 
Nice, thank you! Sorry for the delay I thought I got kicked off.
 
let's say this is the string `Login Code: zemunin-, Speed: 4.09`

looking forward to convert it to be

`Login Code: zemunin , Speed: 4.09`

i used the following code

print(f"Login Code: {k if '-' not in k else k[:-1]}, Speed: {v}")

how to add space then ?
 
print(k.replace('-', ' '))?
 
@roganjosh

print(f"Login Code: {k if '-' not in k else k.replace('-', ''), Speed: {v}")
File "test.py", line 32
print(f'Login Code: {k if "-" not in k else k.replace("-", " "), Speed: {v}')
^
SyntaxError: f-string: expecting '}'
 
Um, no, I meant my code as a complete solution
I didn't mean that you should have it in an f string with logic. It is a solution on its own.
 
5:20 PM
Hmmm
ok
thank you @roganjosh
:D
ops fixed it. were missing '}'
 
But it's over-engineered. You only need to replace one character in the string
nm, I guess you're iterating a dict and haven't shown the full issue
 
6:00 PM
@αԋɱҽԃαмєяιcαη what if your string is "abc-123-456" ?
 
6:54 PM
Caleb, it's an empty text file. As Arab pointed out, is that the reason for the error? — Edward Hutchings 5 mins ago
That's the 2nd time someone turned my name into a nationality :/
 
:(
that checks out with the high rate of typo questions
 
7:13 PM
@user3625380 Yes, dict_of_funcs[your_key](your_args). Note that each of the functions in the dispatch dictionary will need to share the same signature, or at least use *args, **kwargs and default any unsupplied args. It's a little hard at first to make the paradigm shift to Python, functions and lambdas (anonymous fns) are easy to define and use, and don't need all the type-heavy boilerplate of a prototype like they do in Java or C++.
 
7:35 PM
The SO experience
 
def evaluate(expression : str) -> int:
(from elements of progrmaming interviews in python)
what does this mean?
-> i have never seen before
 
is it necessary?
 
nope
 
greeting(name: str)
what does the : do there?
strange notation
 
7:37 PM
it separates
 
could you do greeting(name) instead?
defining types in python seems so weird
 
You're reading awfully fast
 
I will refrain from answering questions that your interpreter can answer for you
 
ahhh
 
 
2 hours later…
10:50 PM
Hi.. um trying to convert some python code and I think I'm mis-understanding how the all() function works
But I have this snippet here:
def wheel(start):
    result = []
    i = start
    for j in range(i + 1, i + 1 + CIRCUMFERENCE):
        if all(j % k for k in BASE_PRIMES):
            result.append(j - i)
            i = j
    return result
My question is, how exactly is the all() function working? does it only execute if and only if every single j % k is true for all k
Or does it loop through them all and check individually
i.e. is result.append(j - i)
i = j
being executed for every time j % k is true, or it's an all or nothing?
For reference looking through this: codereview.stackexchange.com/questions/92365/…
 
11:13 PM
@Rietty it's True if everything inside the iterable is truthy, otherwise False
so yeah, what's inside the if all(...): only executes if every single j % k is truthy (non-zero) for every k
 

« first day (3269 days earlier)      last day (1678 days later) »