« first day (3123 days earlier)      last day (1826 days later) » 

12:00 AM
cbg
 
12:19 AM
don't ping users without context
 
Eeek
 
thanks
 
 
3 hours later…
2:55 AM
cbg
I'll rbrb very soon
and now i rbrb
 
 
2 hours later…
5:16 AM
@MichaelFulton That or super(Derived1, self).func(args)
 
5:27 AM
@ Aran-Fey
test_list = ['man','for']

print("The original list :" + str(test_list))

util_func = lambda x,y: len(x) == len(y)

res = []

for sub in test_list:
ele = next((x for x in res if util_func(sub,x[0])),[])

if ele == []:
res.append(ele)
ele.append(sub)
print(ele)
This code is used to group strings based on the length of the string
I didnt understand this piece of code
ele = next((x for x in res if util_func(sub,x[0])),[]
Could you explain
 
5:39 AM
Well I don't understand the code as a whole, but I suppose I can explain that one line in isolation...
(x for x in res if util_func(sub,x[0])) is a generator expression. Iterating over that generator will yield all x from res for which util_func(sub,x[0]) returns True. And next is a function that gives you the next element from an iterator. So all in all, that line sets ele to the first element in res that has the same length as sub
That code (with added indentation) gives me a result of [['man']]. Is that the intended result...?
 
Yes
 
What about the 'for', though? Why does that disappear?
 
Is it necassary to give lamda function. I tried giving it in a normal function. It didnt work
 
No, not necessary. Anything a lambda can do, a regular function can do as well.
def util_func(x, y):
    return len(x) == len(y)
 
What value would x[0] have. I didnt get that part
sub would be having value "man"
 
5:54 AM
I don't get that part either
whatever it's doing, I'm sure there's a better way to do it
 
recbg
@Aran-Fey except be on one line
 
x for x in res if util_func(sub,x[0])
we have already mentioned res = []
According to my understanding res is empty. Will it compare ("man", EMPTY)
 
6:12 AM
count = 0
how do i create a list having the single value of count , ie, the list would be [0]
 
6:26 AM
@BasilPaul No, if res is empty then the generator expression is also empty and next(..., []) returns its default value []
@kauray [count]?
 
@Aran-Fey yea that worked
I was trying list(count) that was not working
 
list(...) creates a list from an iterable
>>> list('abc')
['a', 'b', 'c']
>>> list(0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'int' object is not iterable
 
thanks!
 
6:56 AM
I have a list l = [[[0], [0, [1], 20], [1, [1], 50], [2, [1], 70], [3, [1], 200]], [[1], [4, [2], 20]]]

and I wish to extract [[[0], [0, [1], 20]], [[1], [4, [2], 20]]] from the list

that is, the first element in the innermost nesting should remain as it is, but for the others, only the list containing the maximum value of the third element should be reatined. How do I do this?
like if l3 = [[[2], [5, [3], 10], [6, [3], 20], [7, [3], 50], [8, [3], 70]], [[3], [9, [4], 20], [10, [4], 50]]]
then the output should be l4 = [[[2], [8, [3], 70]], [[3], [10, [4], 50]]]
 
7:11 AM
I could get as far as [ [sublst for sublst in lst][1:] for lst in l] to extract the non first values
Is this good enough to post as a question?
 
if it helps there's no kind of crap that one can't get upvoted on main :P
At a glance I have no idea what you're trying to do and you should try hard to implement some solution yourself, because otherwise you're dependent on others writing code for you. And if you ask on main you'll only get ready-made solutions.
> for the others, only the list containing the maximum value of the third element should be reatined.
How does the very first [0] count as "containing the maximum value of the third element"?
 
I have written [ max([sublst for sublst in lst][1:])[2] for lst in l]
 
Same in your second example, why are [2] and [3] in there? I don't understand the rule.
 
and i get [200, 20] as the maximum values for l
 
ah
> the first element in the innermost nesting should remain as it is, but for the others,
I missed that part, sorry
 
7:20 AM
ah yes
so mu solution works giving me the maximum value
but i need to output the entire sublist and the first element in tact
 
OK, then you're almost done. But instead of taking [2] outside the max, use the key keyword argument to sort lst[1:] according to their second index
(because [sublst for sublst in lst][1:] is just lst[1:])
are you familiar with sorting/taking maxima and minima using a key function?
 
no i am not
 
Iterables are sorted lexicographically by default, so [1,10] comes before [2,-3] because 1 < 2 is checked first. You can pass a function as the key keyword argument to sorted/min/max to use the value of that function as the basis of sorting/etc.
so you can pass a function key=func in which case things are valued according to func([1,10]) vs func([2,-3]) in the above example
 
I had a general question here! I have seen two types of behaviour on SO, one is where if the question is just an explanation and examples of inputs and outputs, the question is downvoted and closed quite fast, but in some cases, there are atleast 3-4 answers which pop up in a matter of minutes, even from high rep users, and almost no downvote or close vote is cast!
 
for instance you can sort a list according to absolute values like this: sorted([-5,-3,2,-4,1], key=abs)
 
7:25 AM
What is the general accepted behaviour in such cases, because I see both situations almost happening at the same rate!
 
Does this make sense so far?
@DeveshKumarSingh both, the community is divided
Some people want to stop SO from becoming a helpdesk for lazy and incompetent askers, these are the people downvoting and closing effortless questions.
There are others who are either farming for rep, or are just guided some inner motivation for Helping Those In Need who don't care about site quality and motivation and will answer anything.
 
So as a new user what should I do? 1. Don't answer such questions and downvote! 2. Answer such questions so that other people do not beat me to the punch
 
It depends a lot on the tag as well, some tags are more tolerant to laziness than others.
 
@AndrasDeak i understand it to an extend
but cant seem to be able to apply this to the above
 
@DeveshKumarSingh it's up to you to decide how you want to play the game.
@kauray well, one step at a time :)
 
7:27 AM
Which side does sopython falls on?
or the tag python
 
@DeveshKumarSingh I'm not sure there's a clear stand, but if I had to guess more users are worried about crap piling up. In terms of the python tag, that's too large of a bag and you see both.
 
personally, I'm on the "we should close SO and start fresh with higher quality standards" side
 
@kauray so do you understand max([(10, -2), (4,5), ('potato', 0)], key=lambda x:abs(x[0]))?
 
got it, according to the latest survey, python is one of the top tags for which the questions are being asked!
 
@Aran-Fey SO does have higher quality standards. You can have lazy and localized questions that are not inherently crap.
 
7:30 AM
@AndrasDeak that should find the maximum value of the first element of each tuple in the list lexicographically i think
 
@DeveshKumarSingh python is being used more and more both for teaching programming basics and it's being used by people jumping into high-level frameworks such as web dev and machine learning, who don't bother learning the language. This makes for a lot of questions, most of which is low-quality and should be replaced by reading a tutorial.
@kauray run it :)
 
yes but before that, it will calculate the absolute of the first value of the tuple @kauray
do you see an issue there, when it tries to calculate the absolute of that list?
 
oops, wrong example, sorry
I meant to write max([(10, -2), (4,5), ('potato', 0)], key=lambda x:abs(x[1]))
 
shows erroe
yea this should work i think
 
(keyed on first rather than zeroth index)
 
7:32 AM
well the absolute of potato will be potato, since we don't have a negative sign :D
 
@kauray but see that it doesn't return the largest key, it returns the item for which the key is largest
 
oh so it returns the tuple and not just the largest
 
yup
 
ah exactly what u said we typed that together
 
so the key function is used to assign a price to each item in the iterable
(if the price is also an iterable then those are compared lexicographically but you don't need that now)
 
7:33 AM
oh okay
 
Yes, think of key as being a way to perform a comparison on a smaller attribute of a complex datatype
 
so basicaly i can visualize this as a map from a tuple to some value
 
@kauray yup
 
well tuple isn't a complex datatype, but you get the point
 
So the second half of your problem is "find the sublist for which the third element is largest". Do you see where I'm going with this?
 
7:34 AM
so we need to assign this map to each of the sublist with the third element in my case then
 
yup
try playing around with it to see if you can get it to work
it'll be an investment in future programming time and skill
 
okay
 
you should worry about "always keep the first element" later
 
@AndrasDeak out of curiosity, is there a way to overwrite the comparison operators < or >, so that we can also compare strings according to some logic we define on them
 
>>> 'python 2' < 'python 3'
True
no need ^
Strings are iterables so they are sorted lexicographically ;) This of course also means
>>> '20' < '110'
False
 
7:36 AM
I am not talking about lexicographic comparison, which is what happened here I suppose
 
recbg
 
yeah, that was it
 
oh people do use Salad here sometimes
guess i need to learn it
 
it's optional
 
is there a translator somewhere which translates Salad to English, or do I memorize?
 
7:37 AM
there's only a few common terms that people tend to use
 
[ max([sublst for sublst in lst][1:], key=lambda x:x[2]) for lst in l]
[[3, [1], 200], [4, [2], 20]]
 
@DeveshKumarSingh if you don't subclass strings then you're tied to using key rather than comparison operators. There's functools.cmp_to_key which can convert a pairwise comparison to a key , but it's only meant for porting old code from back when the cmp keyword argument existed
@kauray OK, now get rid of [sublst for sublst in lst][1:] ;)
 
I didn't see recbg in the list though, what does it means in English @AnttiHaapala ?
 
it's re + cbg, as people often say re (on IRC mostly) when coming back from afk
 
and re is returned?
 
7:39 AM
or I do
 
@DeveshKumarSingh that's where it's from, yes
 
@DeveshKumarSingh no, re-
 
@AndrasDeak I didnt get it
 
> re- is highly productive, to the point of being almost grammaticalized — almost any verb can have re- applied, especially in colloquial speech. Notable exceptions to this include all forms of be and the modal verbs can, should, etc. When used productively, it is always pronounced /ɹiː/.
 
7:41 AM
so I've applied the re prefix to the contraction of the verb cabbage :P
 
aah got it thanks :)
 
yes i understand i am slicing away the first element
using that
 
thats basically the logic i had tried, slice away the first elemnt then caluclate maximum upon the remaining
 
So, now
1. instead of just keeping the max() for each lst, you want to keep a list of [first item, max]. Try changing that.
2. there's a slightly faster way to write lambda x:x[2], it's operator.itemgetter(2) (for which you have to import the operator module, of course)
but the 2. is more of an FYI, keep using the lambda if you're comfortable with that
 
7:44 AM
thats where i am confused, there would be no max for the first innermost element right?
 
yes, that's why you don't write any max thing there, all this happens outside the max
it's a completely separate expression from the max() part
 
[ max([lst], key = lambda x:x[2]) for lst in l]
this gives me error
 
What did you want that to do?
 
I think the error is because the first element doesnt have [2]
am i right?
 
No, it's because [lst] is a one-length list which doesn't have an index of 2
 
7:49 AM
thats what i meant
 
Another question, more I read about iterators vs generators, more I think they are not very different from each other, what might be the biggest difference between them if I need to just know one difference between them?
 
i probably worded it incorrectly
 
@kauray yup ;)
2 mins ago, by Andras Deak
What did you want that to do?
 
i wanted to map the maximum value to the lists
 
I don't understand that
You already had a working version for that part, right?
 
7:51 AM
oh sorry yea i got confused
however i dont get the removal of the sublist slicing part
 
@DeveshKumarSingh iterator is any construct which satisfies the iterator protocol, a generator is a construct build with a generator expression or a yielding function, which, among other things, satisfies the iterator protocol
 
That's just removing some redundancy. Same result.
[sublst for sublst in lst] is a very slow copy of lst
 
^ good article on the matter
 
and iterator protocol is than we have a class implementing iter and next? What do you mean by iterator protocol @Arne
 
Exactly
 
7:53 AM
@AndrasDeak okay
@AndrasDeak so what would the most efficient solution to my problem look like
 
this article looks interesting, let me read it up, thanks @Arne
 
@kauray well what you had for the max part of the problem was fine if you remove that redundancy
You just have to add code to also keep the first item of each lst
 
how would the first element be retained
yea, thats what i was asking
 
@Arne it is slightly off... a generator function is not a generator, the return value is.
 
Try separately grabbing only the first items, without the max part
 
7:56 AM
@AnttiHaapala good to know
 
It might be easier to combine the two after
 
I'll have to read up what exactly "yield" does... someday
 
@Arne I do not mean a return value but you need to invoke the generator function to get the generator.
>>> def foo():
...     yield 42
...
>>> foo
<function foo at 0x7f5564cfc6e0>
it is just a function.
 
So a generator function is a generator generator :P
 
those are functions that return generators/coroutines
 
7:59 AM
Iterators essentially generate values on demand when we call next on them, and generators do the same thing!
Iterators have some logic defined in their next method, and generators return whatever comes after yield
 
@AndrasDeak you're confusing things here. [lst] is what's fed to max
 
@AnttiHaapala my point exactly?
 
@DeveshKumarSingh if you want to treat generators merely as iterables, then yes
 
@AndrasDeak it is not the one fed to the lambda
 
Oooh you're right, thanks
 
8:01 AM
Which is probably 99% of what other people treat them as
 
@AndrasDeak cant get it to work, could you give me the expression so i can study it?
 
>>> lst = [1,2,3]
>>> max([lst], key=lambda x:x[2])
[1, 2, 3]
 
@kauray [lst[0] for lst in l]
 
it is lst that one needs to consider, not [lst]:P
 
[lst] essentially becomes a list of lists!
 
8:03 AM
@AndrasDeak no not this, this I could extract, i meant the combined solution
 
of course the code still makes zero sense
either the maximum of [lst] is lst or an exception is raised
 
so what else can generators do which iterators cannot @Arne
 
@kauray [[lst[0], max(...)] for lst in l]
 
Sam
Not Python specific but worth a shot. I'm crawling a website to download a bunch of files. To download the files I need to make a bunch of clicks before finally pressing a "download" button which will initiate a download into my /Downloads folder.. I can view the download requested URL but if I were to just make a request (say in URL bar) with that URL, the download does not happen and I get taken to a page which says "the request is not supported".. What could these reasons be?
Could I be missing header information which is only sent with the request from the actual site
 
@AndrasDeak [[lst[0], max([sublst for sublst in lst][1:], key=lambda x:x[2])] for lst in l]
this works for me
u were saying to get rid of the sublst
i couldnt do that
 
8:12 AM
Literaly replace [sublst for sublst in lst] with lst
 
[[lst[0], max(lst[1:], key=lambda x:x[2])] for lst in l]
this works
oh i see, let me translate, we are iterating over each lst in l, and for each lst we are slicing off the first element, then assigning the map with lambda and then take the maximum value
is this what i understand correct?
 
I think so, yes
 
thanks
 
no problem
@AnttiHaapala that's what I get for debugging from mobile ;)
 
i know basic python, hoever get confuded with these multi dimensional stuff, any good resources for these stuff?
 
8:20 AM
I don't know of any, sorry. I have formal training in solving complicated multidimensional problems :)
 
cool
 
this is probably a skill that will grow with practice
Try to analyze the problem, decouple it into smaller blocks and handle each separately. That's why I suggested solving the two parts separately.
 
@kauray A good exercise for you is to maybe try to write this list comprehension @AndrasDeak suggested using traditional for loops
 
Once you have [lst[0] for lst in l] and [max(...) for lst in l] it might easier to see that for each lst you just have to combine the two in a 2-length list.
 
so you can understand at each step what is going on, use a IDE like PyCharm for debugging if you want to
 
8:22 AM
@DeveshKumarSingh yeah, that can help, although if the for loop contains two or three statements before the .append it can also be hard for a newbie to refactor into a list comp
then again for loops aren't evil, one should first write working code and then try improving from there
 
i guess i will get some practise, this is just a small piece of a larger problem i am trying to solvve
 
I suspected :)
 
Yes, I think jumping directly into list-comprehension might be harder for a newbie, once you get into 2-3 loops deep
It is harder still for me to grasp them haha
 
I wouldn't suggest nested listcomps to a newbie.
those are rarely a good idea anyway
 
@kauray if you can try to write a simple looping idea about this problem, you will understand how @AndrasDeak went from there to the one liner he has :)
 
8:24 AM
should i use a chatroom with someone instead of cluttering the chat here for these things?
@DeveshKumarSingh yea i am able to come up with looping solutions to some of these, but not able to get these one liners or compact ones
 
Well, yeah, longer discussions can be noisy here, but I think this one was acceptable. Then again SO is not really about one-to-one tutoring so it's not very idiomatic to find someone to help you in a separate chatroom. But if you can pull that off nobody will mind, I guess.
note that it's hard to ask "will someone please come with me to a separate room to help me write this code" without being off-putting :)
 
hmm cool
 
Yes, and as always, nothing beats just asking a Question on Stack Overflow , because remember StackOverflow is a Q&A site, and chatrooms are just an added feature!
 
asking on SO main is a double-edged sword especially if you have no idea what to do
 
Okay that's nice @kauray Also remember that if you can do something with simple loops, you can leave that there if you want some other newbie to be able to read your code!
 
8:28 AM
If you frequently need small-scale help with non-trivial problems then SO is not the right place. Codementor and other help-oriented fora are much better for this.
 
Or maybe break some of the simpler things to list comprehension! and leave the rest as-is, the choice is yours
 
okay
 
That being said, you'll notice if you're becoming a burden, we are very explicit about that. And I usually don't mind helping people who make an effort to understand and learn :)
 
Cool, and if you ask questions on SO, maybe newbie users like me can earn some repo from answering them :D
 
dude, you have 6k rep from
 
8:31 AM
When I say newbie, I meant I only started using the site last month properly!
 
Oh?
I see
 
but I made an account like a while back! But I use SO to primarily learn python, and I actually realized how powerful this language is!
And somehow, I am #3 in weekly rankings for SO, which means I need to get a life outside SO :D
 
and to make sure you don't answer low-quality questions
 
I did not get that part! Yes I mostly ask for clarifications in comments from them! And if they provide enough, answer them
I guess that's acceptable in SO
And I assume low quality is a homework dump, or just expected inputs and outputs, or almost no code or missing code!
 
@DeveshKumarSingh just general guidance. I didn't look at what you answered, I just saw that you've been gathering 300-400 rep a day (which works out with 6k rep in a month).
I should've added "and duplicates" which is the other pet peeve of users worrying about site quality :)
 
8:40 AM
Understood! Well maybe from a higher rep user like you, going forward what should be the key of gaining rep in a fair manner gradually! apart from not answering low quality and duplicate questions!
 
I'm not the one to ask, I don't care much for rep and I'm very grumpy about site quality
if you don't answer low-quality poop and dupes you're mostly safe from the likes of me
and of course use your close votes generously when necessary
rhubarb
 
@DeveshKumarSingh they can be used as subprocesses, where you yield information back into them while the generator is active
I have never seen it in the wild yet
s/subprocess/subroutine/
python.org/dev/peps/pep-0342 introduced the behavior
 
9:31 AM
is it bad style to import libs later in the code and not on top? For example if I need to change the matplotlib backend depending on a variable I would import it only in the function that uses it with the needed backend not on top, but I wonder if that is bad style
ala
def do_stuff():
   a = True
   if a:
      import matplotlib
      matplotlib.use('Agg')
   import matplotlib.pyplot as plt
 
10:19 AM
@Hakaishin it's usually to be avoided but if you can only decide the backend during runtime then there's no other way I think
 
I see. I just don't see how I could avoid it. If I want to save plots into a video file I need to use Agg, otherwise I get an error every now and then and if I want to visualize the plots I need the default backend
 
 
2 hours later…
12:20 PM
hey
how to query from this
x = {'test1': Table('test1', MetaData(bind=None), Column('id', INTEGER(), table=<test1>, nullable=False, server_default=DefaultClause(<sqlalchemy.sql.elements.TextClause object at 0x000001F83BCAEC50>, for_update=False)), Column('name', VARCHAR(), table=<test1>, nullable=False), schema=None), 'test2': Table('test2', MetaData(bind=None), Column('id2', INTEGER(), table=<test2>, nullable=False, server_default=DefaultClause(<sqlalchemy.sql.elements.TextClause object at 0x000001F83BCCEA58>, for_update=False)), Column('name2', VARCHAR(length=200), table=<test2>, nullable
 
12:36 PM
when i try to print x['test1'] i got a syntax error
that is the full post stackoverflow.com/questions/55987726/flask-sqlalchemy-automap-external-database
AttributeError: 'dict' object has no attribute 'test1'
 
12:52 PM
Are you sure you're not trying x.test1 instead?
Or that the print is causing the (non-syntax!) error?
I'm skeptical
 
iam sure
 
1:21 PM
@za001a we ask that you don't ask for help with fresh questions you've asked on main. Regarding your question, you should edit it and add the actual error message you get, especially since it's not a syntax error.
 
SyntaxError: invalid syntax
pointing on print(x['test1'])
on the other hand on browser it says
AttributeError: 'dict' object has no attribute 'test1'
 
You should reduce that to one error message per code
 
huh?
 
1:37 PM
You can't have both a syntax error and an attribute error from the same line of code
Given our history I don't believe you without a full traceback. And anyway this info should go in your question, not here
 
 
2 hours later…
4:07 PM
there's something ironic about the sphinx and docutils documentation being so poor
 
 
1 hour later…
5:31 PM
SORRY I WAS IN A MEETING
SyntaxError: invalid syntax that is the correct error
pointing to print(f'\n\n tables test1 = { x['test1'] } \n\n')
 
what is the python version?
 
This is the quotes problem, even in 3.6
 
oooh, right
didn't notice that
 
5:52 PM
or is there a better canonical?
sorry, wrong link
 
Something like that I'd still be inclined to write as: print('\n\n tables test1 =', x['test1'], '\n\n') or print('\n\n tables test1 = {test1} \n\n'.format_map(x)) depending... I wouldn't necessarily jump to using an f-string there...
 
ohh simply unquoted single quotes within single quotes, sorry, missed that too!
 
6:25 PM
cbg
 
wim
what the "which badger to use for hammer" algorithm? is it alphabetical? call different functions for list elements [duplicate]
 
Cabbage
 
@wim unclear / no MCVE (your chat message I mean)
do you mean which badge will it display when a gold badge holder hammers? I don't think we have enough data to conclude anything but this is a known bug
the examples I can find seem consistent with the alphabetical hypothesis
 
@wim it's the badge held by the fewest number of people...
@wim so basically the order the gold tag badges get listed on stackoverflow.com/users/674039/wim?tab=badges
 
6:39 PM
.oO (my ultimate goal is still to get gold in )
 
@tripleee that looks like it'd be a remarkable achievement :p
 
"aim for the impossible and you will achieve the improbable" (-:
 
okay... :p
 
cbg
 
wim
7:06 PM
@JonClements really?! weird choice
they should just list all of them
>>> L = [float('nan')]
>>> L == L
True
>>> json.loads(json.dumps(L)) == L
False
 
Some people have argued that the least common "language" tag should be used as that's more likely to be the specific knowledge of the closure... else for things like "list", "string" and "tuple" etc... you can end up closing shed loads of stuff without really knowing a thing about it specifically :p
(but there's no distinction in tags between a language/types/libraries/common data structures etc...)
 
7:47 PM
Is this an good program for finding n! where n can be 1e6 and number of test cases can be 1e5? I'm using memoization here.
facto = [0]*1000001
facto[0]=facto[1]=1
def fact(n):
    global facto
    if(facto[n]>0):
        return facto[n]
    else:
        f = (n*fact(n-1))
        facto[n]=f%1000000007
    return f%1000000007

#print(fact(5))
t = int(input())
for _ in range(t):
    n = int(input())
    print(fact(n))
 
7:59 PM
How's your recursion depth for n=1_000_000?
 
try fact(1000), you'll probably see the recursion limit being hit
 
I'd have thought overall - just calling math.factorial as you need it would be reasonable enough... not sure memoization is of any real benefit and just more a pain here...
 
@AndrasDeak Yeah :P
@JonClements Tried that, it is not giving o/p within 1 sec for that huge numbers and number of inputs
 
well you're asking it to compute something difficult
 
8:05 PM
I have used PYPY 3, I heard that is the fastest
 
1000000! is around 10^5565700
 
Well... say your first entry is 10000! - that's a rather large number... if that's the smallest number present, storing the results of 1..9999! is just memory overhead...
 
@JonClements That's why using(n!)%1000000007
 
And if 10000! only appears once - then it's pointless caching it...
I'm sure it's possible to do a few clever things... but I don't think they'd end up helping at all
but yeah... definitely get rid of that recursion :)
 
well at least the for loop at the bottom suggests that they're asking multiple factorials so memoization would speed up that part
 
8:09 PM
@JonClements Can you tell some idea?
@AndrasDeak Yeeah, that's why used memoization
 
@AndrasDeak not necessarily
 
Not necessarily what?
Doesn't it suggest it, or won't it speed it up? Because I'm pretty certain in the latter.
 
fairly sure it's likely to not speed it up...
 
if you have n1 > n2 then fact(n1) involves computing fact(n2) at which point fact(n2) is a single lookup
otherwise you still only have to compute fact(k) from k=n1..n2 as opposed to k=1..n2
 
umm... except will it? My brain's slowing down... (if it ever worked that is :p)
do you really efficiently get to the point of starting from fact(n2)...
 
8:18 PM
You try computing fact(n2), defer to fact(n2-1), then to fact(n2-2) ... until you find one value for which fact(k) is already computed.
So you'll have fact(k) computed for k = max(inputs_so_far) (and each exactly once)
 
yeah... but if your first entry in the input is 1e4 and there's nothing lower than that in the input, then you've memorised everything prior to that unnecessarily... when you could have just started off straight away with fact(1e4) and use that as your base...
I'm kinda thinking along the lines of sorting the input... compute the fact of the min number... then keep reducing that with the range between it and the next number in the input, repeat
 
@JonClements well, yeah. We're talking about the specific implementation, complete with its drawbacks. But assuming this implementation, memoization makes it faster for multiple calls to fact().
I don't think memoization is the weakest link here
 
Well maybe iteration with memoization?
 
I think you should implement a simplest version that works for 1e6-sized input, then worry about making it faster
 
8:26 PM
and you can test correctness with math.factorial(1000) which is a reasonably large number
 
@AndrasDeak I need n!%1000000007, so the answer will be atmost 1e9+6
 
How do you intend to test your n!%1000000007 numerically? Compare it to what?
I'm saying math.factorial(1_000_000) % 1000000007 is probably not what you want to do
 
Why there are _s ? Is it not same as 1000000 ?
 
it is, just more readable
the syntax was introduced in...python 3.6, I think?
 
8:51 PM
How to deal with an old popular XY-problem question with a high voted accepted, but incomplete answer which needlessly shoehorns a feature into something (multiprocessing.Pool) which already exists by default? I dropped a counter-answer but despite the fact that I gave a complete working answer with background-info, it doesn't look like it has a chance to be taken serious alongside the accepted answer.
 
if you're lucky you might find a duplicate so you can close it... but the usual solution is to ignore it I think
 
It's a popular dupe-target itself that's the problem. Always wondered how people came up with this setup before I found this question.
 
if you're super desperate, you can make a meta post and pray
but frankly, out of the two, praying is the more effective one
 
I share your optimism regarding meta ;)
 
9:32 PM
you should just listen to some queen and Let it gooo...
 
Well it's not my problem really, but people new to this topic pick this example up and than ask new questions because it doesn't work as expected.
 
if it makes you feel any better people ask new questions even for problems that are trivial to google
 
It doesn't, but thx for trying ;)
 
 
1 hour later…
10:52 PM
Does anyone know how to use bow with orb? I'm doing some tests and I do not understand where the error comes from
 
11:26 PM
@Joc1240 sounds like you're playing a multi-user dungeon game or something :)
 
cbg
 

« first day (3123 days earlier)      last day (1826 days later) »