Re: We will be moving to GitHub
Steven D'Aprano : > Oh, and talking about DVCS: > > https://bitquabit.com/post/unorthodocs-abandon-your-dvcs-and-retur > n-to-sanity/ It's interesting how different opinions people can have about version control. I also have mine. I have seen the paradise, which was Sun's Teamware. I haven't tried Bitkeeper, it's successor. Having struggled with Perforce, SVN and CVS, I was hopeful Mercurial would be everything Teamware was. Unfortunately, it wasn't. The big disappointment was the treatment of a repository as the atomic unit. Git's no better than Mercurial. Also, Git is conceptually cluttered. Well, Git and Mercurial are not all that bad as long as only a single person is working on the repository at any given time and you have a strictly linear version history. That would be advisable anyway as you should have a separate repository for each conceptual unit. Marko -- https://mail.python.org/mailman/listinfo/python-list
Re: We will be moving to GitHub
On Sat, Jan 2, 2016 at 8:48 PM, Marko Rauhamaa wrote: > Having struggled with Perforce, SVN and CVS, I was hopeful Mercurial > would be everything Teamware was. > > Unfortunately, it wasn't. The big disappointment was the treatment of a > repository as the atomic unit. You'll need to elaborate on this. Is a repository too large or too small as an atomic unit? What is the Teamware style, and what is the advantage? Remember, you can always build structures around the outside of a repository - hg.python.org has half a dozen major repos, plus a large number of others. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: We will be moving to GitHub
Chris Angelico : > On Sat, Jan 2, 2016 at 8:48 PM, Marko Rauhamaa wrote: >> Having struggled with Perforce, SVN and CVS, I was hopeful Mercurial >> would be everything Teamware was. >> >> Unfortunately, it wasn't. The big disappointment was the treatment of >> a repository as the atomic unit. > > You'll need to elaborate on this. Is a repository too large or too > small as an atomic unit? If a repository contains independent changes, Hg and Git fail to understand that the changes could be independent and force you to resolve a merge conflict where no real conflict exists. The whole philosophy of dependent and independent changes is complicated; only Darcs has attempted to address the issue scientifically (http://darcs.net/Theory/GaneshPatchAlgebra>). However, Teamware chose an opportune approximation by treating each file's version history independently. Teamware's approach works nicely for backporting. You often fix a bug in the development version and would like to propagate the fix to an older version (= branch/stream/fork) of the product. In Teamware, the propagation would not generate a conflict so it doesn't need to be resolved. No special cherrypicking is involved, and afterwards, you can't tell if the change was made first to the old version/branch/stream/fork or the new one. (Teamware didn't have branches. It always used forks. I believe Hg is/was the same way. Git, which is what I have to use nowadays, has branches but I find little use for them.) Marko -- https://mail.python.org/mailman/listinfo/python-list
Re: We will be moving to GitHub
On Sat, Jan 2, 2016 at 10:22 PM, Marko Rauhamaa wrote: > Chris Angelico : > >> On Sat, Jan 2, 2016 at 8:48 PM, Marko Rauhamaa wrote: >>> Having struggled with Perforce, SVN and CVS, I was hopeful Mercurial >>> would be everything Teamware was. >>> >>> Unfortunately, it wasn't. The big disappointment was the treatment of >>> a repository as the atomic unit. >> >> You'll need to elaborate on this. Is a repository too large or too >> small as an atomic unit? > > If a repository contains independent changes, Hg and Git fail to > understand that the changes could be independent and force you to > resolve a merge conflict where no real conflict exists. > > The whole philosophy of dependent and independent changes is > complicated; only Darcs has attempted to address the issue > scientifically (http://darcs.net/Theory/GaneshPatchAlgebra>). > However, Teamware chose an opportune approximation by treating each > file's version history independently. I don't think you understand the meaning of "merge conflict", then. A merge conflict is when you cannot simply merge the changes. If the changes are on separate files, neither git nor hg will find this to be a conflict, and the merge will happen automatically. Alternatively, you can rebase rather than merging (git's term; Mercurial has a similar concept for saying "put my private changes on top of the history", but I can't remember the name), which again will succeed automatically if the changes are to different files. Even better, the merge/rebase will generally succeed even if the changes are to the same file, as long as they're to different parts of it. Play to a tool's strengths rather than its weaknesses, and you'll find life a lot less frustrating. I'm fairly sure you could use the same workflow with git as you were accustomed to with Teamware, only with a few different names for things. And most likely Mercurial too, but again, there'll be different names. Maybe you'll use branches for what you used to use forks for, or maybe you'll have multiple clones of the same repository, or maybe some other arrangement. Get to know some of the myriad ways you can use modern source control systems, and find a workflow that suits you. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: raise None
On 31.12.2015 21:18, Ben Finney wrote: > As best I can tell, Steven is advocating a way to obscure information > from the traceback, on the assumption the writer of a library knows that > I don't want to see it. How do you arrive at that conclusion? The line that raises the exception is exactly the line that you would expect the exception to be raised. I.e., the one containing the "raise" statement. What you seem to advocate against is a feature that is ALREADY part of the language, i.e. raising exceptions by reference to a variable, not constructing them on-the-go. Your argumentation makes therefore no sense in this context. Cheers, Johannes -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht öffentlich! Ah, der neueste und bis heute genialste Streich unsere großen Kosmologen: Die Geheim-Vorhersage. - Karl Kaos über Rüdiger Thomas in dsa -- https://mail.python.org/mailman/listinfo/python-list
Trailing zeros of 100!
Hi, newbie here! I'm trying to write a python program to find how many trailing zeros are in 100! (factorial of 100). I used factorial from the math module, but my efforts to continue failed. Please help. Thank you, Yehuda -- https://mail.python.org/mailman/listinfo/python-list
Re: Trailing zeros of 100!
On 2 January 2016 at 22:49, wrote: > Hi, newbie here! Hi Yehuda > I'm trying to write a python program to find how many trailing zeros are in > 100! (factorial of 100). > I used factorial from the math module, but my efforts to continue failed. > Please help. There is a special mailing list to help newbies write code: https://mail.python.org/mailman/listinfo/tutor Subscribe to that list and post whatever *code you have already written* there, and explain exactly how you want it to be better. -- https://mail.python.org/mailman/listinfo/python-list
Re: Trailing zeros of 100!
On Saturday, January 2, 2016 at 1:49:47 PM UTC+2, katy...@gmail.com wrote: > Hi, newbie here! > I'm trying to write a python program to find how many trailing zeros are in > 100! (factorial of 100). > I used factorial from the math module, but my efforts to continue failed. > Please help. > > Thank you, > Yehuda Thank ou, David, for your help and kindness. -- https://mail.python.org/mailman/listinfo/python-list
Re: Trailing zeros of 100!
2016-01-02 12:49 GMT+01:00 : > Hi, newbie here! > I'm trying to write a python program to find how many trailing zeros are in > 100! (factorial of 100). > I used factorial from the math module, but my efforts to continue failed. > Please help. > > Thank you, > Yehuda > -- > https://mail.python.org/mailman/listinfo/python-list Hi, rather an illustration of the available tools in python, than a (submittable) solution: >>> import re, math >>> len(re.search(r"0*$", str(math.factorial(100))).group()) 24 [or the same code on more lines with some indentation - if it is preserved via e-mail] >>> len( ... re.search( ... r"0*$", ... str( ... math.factorial(100) ... ) ... ).group() ... ) 24 >>> I.e. You need the length of the string resulting as the match of the regular expression search for a pattern representing zero or more "0" at the end of the input text, which is the string version of 100! Of course, there are other ways to get this result :-) regards, vbr -- https://mail.python.org/mailman/listinfo/python-list
What meaning is '[: , None]'?
Hi, I read a code snippet, in which object w_A is: w_A Out[48]: array([ 0.10708809, 0.94933575, 0.8412686 , 0.03280939, 0.59985308]) Then, I don't know what is '[: ' below: vs_A = w_A[:, None] * xs I don't find the answer after searching around Could you explain above code to me? Thanks, -- https://mail.python.org/mailman/listinfo/python-list
Re: We will be moving to GitHub
Chris Angelico : > I don't think you understand the meaning of "merge conflict", then. A > merge conflict is when you cannot simply merge the changes. A conflict is when there have been two parallel changes to the same versioned target. In the case of Hg and Git, the whole repo is the target. > If the changes are on separate files, neither git nor hg will find > this to be a conflict, and the merge will happen automatically. They can propose to resolve the conflict automatically, which, BTW, undermines the very idea of treating the whole repo as an atomic target. Hg and Git think it's too dangerous to trust changes to individual files are independent, but then, the alleviate the resulting pain, they offer to treat the changes independently anyway, giving you the downsides while sacrificing the (purported) upsides. > Alternatively, you can rebase rather than merging (git's term; > Mercurial has a similar concept for saying "put my private changes on > top of the history", but I can't remember the name), which again will > succeed automatically if the changes are to different files. Even > better, the merge/rebase will generally succeed even if the changes > are to the same file, as long as they're to different parts of it. In Teamware, push ("putback") will simply succeed without any need to resolve the merge conflict (automatically, or otherwise). > Play to a tool's strengths rather than its weaknesses, and you'll find > life a lot less frustrating. I'm fairly sure you could use the same > workflow with git as you were accustomed to with Teamware, only with a > few different names for things. And most likely Mercurial too, but > again, there'll be different names. Maybe you'll use branches for what > you used to use forks for, or maybe you'll have multiple clones of the > same repository, or maybe some other arrangement. Get to know some of > the myriad ways you can use modern source control systems, and find a > workflow that suits you. As I said, the problem is nonexistent when your repositories are tiny (~ 5-20 files) and each is actively maintained by a single person. Marko -- https://mail.python.org/mailman/listinfo/python-list
Re: Trailing zeros of 100!
Vlastimil, Thank you so much, but... All that is Chinese for me. Can you show a 'normal' Python code for me? Yehuda On Sat, Jan 2, 2016 at 2:44 PM, Vlastimil Brom wrote: > 2016-01-02 12:49 GMT+01:00 : > > Hi, newbie here! > > I'm trying to write a python program to find how many trailing zeros are > in 100! (factorial of 100). > > I used factorial from the math module, but my efforts to continue > failed. Please help. > > > > Thank you, > > Yehuda > > -- > > https://mail.python.org/mailman/listinfo/python-list > > Hi, > rather an illustration of the available tools in python, than a > (submittable) solution: > > >>> import re, math > >>> len(re.search(r"0*$", str(math.factorial(100))).group()) > 24 > [or the same code on more lines with some indentation - if it is > preserved via e-mail] > >>> len( > ... re.search( > ... r"0*$", > ... str( > ... math.factorial(100) > ... ) > ... ).group() > ... ) > 24 > >>> > > I.e. You need the length of the string resulting as the match of the > regular expression search for a pattern representing zero or more "0" > at the end of the input text, which is the string version of 100! > > Of course, there are other ways to get this result :-) > > regards, > vbr > -- https://mail.python.org/mailman/listinfo/python-list
Re: Python Data Analysis Recommendations
I also collect data by sweeping multiple parameters in a similar fashion. I find pandas very convenient for analysis. I don't use all the features of pandas. I mainly use it for selecting certain rows from the data, sometimes using database style merge operations, and plotting using matplotlib. This can also be done using pure numpy but with pandas, I don't have to keep track of all the indices This is what my workflow is like (waarning - sloppy code): data = pd.DataFrame() data.columns = ['temperature', 'voltage_measured', 'voltage_applied', 'channels'] for channel in data.channels.unique(): for temperature in data.temperature.unique(): slope = fit_slope(data[data['temperature']==temperature and data['channels']==channel]) # fit_slope(x) -> fits x.voltage_measured and x.voltage_applied and returns slope # append (channel, temperature, slope) to final plotting array etc I imagine your database driven approach would do something similar but you might find pandas more convenient given that it can all be done in python and that you won't have to resort to SQL queries. My data is small enough to get away with storing as plain text. But hdf5 is definitely a better solution. In addition to pytables, there is also h5py (http://www.h5py.org/). I prefer the latter. You might like pytables because it is more database-like. Sameer On 31 December 2015 at 22:45, Rob Gaddi wrote: > I'm looking for some advice on handling data collection/analysis in > Python. I do a lot of big, time consuming experiments in which I run a > long data collection (a day or a weekend) in which I sweep a bunch of > variables, then come back offline and try to cut the data into something > that makes sense. > > For example, my last data collection looked (neglecting all the actual > equipment control code in each loop) like: > > for t in temperatures: > for r in voltage_ranges: > for v in test_voltages[r]: > for c in channels: > for n in range(100): > record_data() > > I've been using Sqlite (through peewee) as the data backend, setting up > a couple tables with a basically hierarchical relationship, and then > handling analysis with a rough cut of SQL queries against the > original data, Numpy/Scipy for further refinement, and Matplotlib > to actually do the visualization. For example, one graph was "How does > the slope of straight line fit between measured and applied voltage vary > as a function of temperature on each channel?" > > The whole process feels a bit grindy; like I keep having to do a lot of > ad-hoc stitching things together. And I keep hearing about pandas, > PyTables, and HDF5. Would that be making my life notably easier? If > so, does anyone have any references on it that they've found > particularly useful? The tutorials I've seen so far seem to not give > much detail on what the point of what they're doing is; it's all "how > you write the code" rather than "why you write the code". Paying money > for books is acceptable; this is all on the company's time/dime. > > Thanks, > Rob > > -- > Rob Gaddi, Highland Technology -- www.highlandtechnology.com > Email address domain is currently out of order. See above to fix. > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: We will be moving to GitHub
On Sat, Jan 2, 2016 at 5:12 AM, Chris Angelico wrote: > On Sat, Jan 2, 2016 at 5:43 PM, Steven D'Aprano wrote: >> There are times where everybody should do the same thing -- choosing whether >> to drive on the left or the right side of the road, for example. And there >> are times where following the crowd like lemmings is actively harmful, no >> matter how convenient it seems in the short-run. > > The popularity of technology IS an argument in its favour, though. How > many people here use Gopher instead of HTTP? Would it be better to > serve Python content on the obscure protocol rather than the popular > one? When 99% of people know how to use one technology and 1% know how > to use a different one, it's advantageous to go where the people are. > (Of course, there are other considerations, too - PHP is popular, but > that alone isn't a reason to use it. The context here is of > technologies so similar in functionality that we really CAN make a > decision on these kinds of bases.) > > The Python project *needs* new contributors. This is not in question. > You can't expect to keep the project going solely on the basis of the > people currently writing and applying patches. So there are two > options: > I must agree with Chris, visibility in OSS is key of it. If you write a library and license it under BSD 3-Clause but keep it in your local network forever it is not as open as if you would throw it in GitHub. There are many people there, and there are many people willing to at least review the code of interesting projects. -- https://mail.python.org/mailman/listinfo/python-list
Re: We will be moving to GitHub
On Sun, Jan 3, 2016 at 1:26 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> I don't think you understand the meaning of "merge conflict", then. A >> merge conflict is when you cannot simply merge the changes. > > A conflict is when there have been two parallel changes to the same > versioned target. In the case of Hg and Git, the whole repo is the > target. No, that's just a merge. https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: We will be moving to GitHub
Chris Angelico : > On Sun, Jan 3, 2016 at 1:26 AM, Marko Rauhamaa wrote: >> A conflict is when there have been two parallel changes to the same >> versioned target. In the case of Hg and Git, the whole repo is the >> target. > > No, that's just a merge. > > https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging Terminology aside, if I do this with Git: -++> \ ^ \pull /push v / +--+ edit everything goes in without any further ado. However, this operation will be blocked by Git: --+--+++---> \ \ ^X \ \pull /push/ \ v // pull\ +--+/push \ edit / v / +-+ Not so by Teamware as long as the pushes don't have files in common. Marko -- https://mail.python.org/mailman/listinfo/python-list
Re: Trailing zeros of 100!
On Sat, Jan 2, 2016 at 8:14 AM, yehudak . wrote: > Vlastimil, > Thank you so much, but... > All that is Chinese for me. > Can you show a 'normal' Python code for me? > > Yehuda > > On Sat, Jan 2, 2016 at 2:44 PM, Vlastimil Brom > wrote: > > > 2016-01-02 12:49 GMT+01:00 : > > > Hi, newbie here! > > > I'm trying to write a python program to find how many trailing zeros > are > > in 100! (factorial of 100). > > > I used factorial from the math module, but my efforts to continue > > failed. Please help. > > > > > > Thank you, > > > Yehuda > > > -- > > > https://mail.python.org/mailman/listinfo/python-list > > > > Hi, > > rather an illustration of the available tools in python, than a > > (submittable) solution: > > > > >>> import re, math > > >>> len(re.search(r"0*$", str(math.factorial(100))).group()) > > 24 > > [or the same code on more lines with some indentation - if it is > > preserved via e-mail] > > >>> len( > > ... re.search( > > ... r"0*$", > > ... str( > > ... math.factorial(100) > > ... ) > > ... ).group() > > ... ) > > 24 > > >>> > > > > I.e. You need the length of the string resulting as the match of the > > regular expression search for a pattern representing zero or more "0" > > at the end of the input text, which is the string version of 100! > > > > Of course, there are other ways to get this result :-) > > > > regards, > > vbr > > > -- > https://mail.python.org/mailman/listinfo/python-list > Can you improve your question? Which python version, which os are standard to tell. Also, show the code you have written, its output, and what you think is wrong with it. This might be homework, since it is a very contrived problem. But to push you forward: Can you get the factorial? Can you get the string of that result? Do you know about lists, and slicing, and reversing a list (hint: a = "123", b = a[::-1] will return "321" If you know these concepts, and know how to loop and count, you can solve your puzzle -- Joel Goldstick http://joelgoldstick.com/stats/birthdays -- https://mail.python.org/mailman/listinfo/python-list
Re: We will be moving to GitHub
On Sun, Jan 3, 2016 at 1:52 AM, Marko Rauhamaa wrote: > Terminology aside, if I do this with Git: > >-++> > \ ^ > \pull /push >v / >+--+ > edit > > everything goes in without any further ado. > > However, this operation will be blocked by Git: > > >--+--+++---> > \ \ ^X >\ \pull /push/ > \ v // > pull\ +--+/push > \ edit / >v / >+-+ > > Not so by Teamware as long as the pushes don't have files in common. Ah, I see what you mean. That's a constantly-debated point, and it's actually possible to make git accept this, although it's not a normal workflow. Instead, you just 'git pull' (possibly with --rebase) before you 'git push'. You either create a new merge commit, or make it very clear that you are changing your commits to pretend they were committed after the already-pushed ones. Or you do a force-push and discard the other commits (this is correct if you amended a commit). You HAVE to choose because these are three viable solutions, and only a human can make the decision. Teamware presumably picked one of them, and doesn't give you the other two choices. The price you pay for power is complexity. But with a little bit of tooling, you can hide that complexity from day-to-day usage - it means writing a git hook, but don't be scared off by that; they're just simple scripts! ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Trailing zeros of 100!
2016-01-02 14:14 GMT+01:00 yehudak . : > Vlastimil, > Thank you so much, but... > All that is Chinese for me. > Can you show a 'normal' Python code for me? > > Yehuda > > On Sat, Jan 2, 2016 at 2:44 PM, Vlastimil Brom > wrote: >> >> 2016-01-02 12:49 GMT+01:00 : >> > Hi, newbie here! >> > I'm trying to write a python program to find how many trailing zeros are >> > in 100! (factorial of 100). >> > I used factorial from the math module, but my efforts to continue >> > failed. Please help. >> > >> > Thank you, >> > Yehuda >> > -- >> > https://mail.python.org/mailman/listinfo/python-list >> >> Hi, >> rather an illustration of the available tools in python, than a >> (submittable) solution: >> >> >>> import re, math >> >>> len(re.search(r"0*$", str(math.factorial(100))).group()) >> 24 >> [or the same code on more lines with some indentation - if it is >> preserved via e-mail] >> >>> len( >> ... re.search( >> ... r"0*$", >> ... str( >> ... math.factorial(100) >> ... ) >> ... ).group() >> ... ) >> 24 >> >>> >> >> I.e. You need the length of the string resulting as the match of the >> regular expression search for a pattern representing zero or more "0" >> at the end of the input text, which is the string version of 100! >> >> Of course, there are other ways to get this result :-) >> >> regards, >> vbr > > Hi, If you eventually have this as an assignment or other kind of (self)learning task, you would want to approach this with the methods you know, or are supposed to use. For the math context, you may find this explanations useful: http://www.purplemath.com/modules/factzero.htm a rather straightforward python implementation of this seems to be e.g. this recipe: http://code.activestate.com/recipes/577844-calculate-trailing-zeroes-in-a-factorial/ Note, that you don't need to calculate the value of the factorial itself using this way. If you have problems with following or understanding the code, you may show your own attempts and tell what problems you encounter with your approach. My previous code sample is based on another - "brute-force" approach, the factorial is calculated (e.g. via the math module as you have found), then the integer is converted to a string, afterwards the part of the result consisting only of zeros - at the end of the string is matched with a regular expression and finally the length of it is determined. Regular expressions might be handy, but are not necesarilly elementary stuff for a newcomer in python programming. You can count the trailing zeros in other ways too - as was suggested - you can reverse the string and count from the beginning then, stopping before the first non-zero digit. The most straightforward way could be to loop (characterwise) through the (reversed) string, check each character whether it equals to "0" and stop as soon as there is another digit. hth, vbr -- https://mail.python.org/mailman/listinfo/python-list
Re: Trailing zeros of 100!
On 02/01/2016 13:14, yehudak . wrote: Vlastimil, Thank you so much, but... All that is Chinese for me. Can you show a 'normal' Python code for me? Yehuda On Sat, Jan 2, 2016 at 2:44 PM, Vlastimil Brom wrote: 2016-01-02 12:49 GMT+01:00 : Hi, newbie here! I'm trying to write a python program to find how many trailing zeros are in 100! (factorial of 100). I used factorial from the math module, but my efforts to continue failed. Please help. Thank you, Yehuda -- https://mail.python.org/mailman/listinfo/python-list Hi, rather an illustration of the available tools in python, than a (submittable) solution: import re, math len(re.search(r"0*$", str(math.factorial(100))).group()) 24 [or the same code on more lines with some indentation - if it is preserved via e-mail] len( ... re.search( ... r"0*$", ... str( ... math.factorial(100) ... ) ... ).group() ... ) 24 I.e. You need the length of the string resulting as the match of the regular expression search for a pattern representing zero or more "0" at the end of the input text, which is the string version of 100! Of course, there are other ways to get this result :-) regards, vbr I'll explain it if you stop top posting. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: What meaning is '[: , None]'?
On Sat, 2 Jan 2016 11:44 pm, Robert wrote: > Hi, > > I read a code snippet, in which object w_A is: > > > w_A > Out[48]: array([ 0.10708809, 0.94933575, 0.8412686 , 0.03280939, > 0.59985308]) w_A looks like a numpy array of five values. http://docs.scipy.org/doc/numpy/reference/arrays.html > Then, I don't know what is '[: ' below: > vs_A = w_A[:, None] * xs The syntax w_A[ ... ] is a "slice" of array w_A. Slicing means to create a new array from part of the original. None inside a numpy slice behaves as an alias for numpy.newaxis. http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html In this case, w_A[:, None] returns a "view" of the original w_A array. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: What meaning is '[: , None]'?
On Saturday, January 2, 2016 at 6:14:24 PM UTC+5:30, Robert wrote: > Hi, > > I read a code snippet, in which object w_A is: > > > w_A > Out[48]: array([ 0.10708809, 0.94933575, 0.8412686 , 0.03280939, > 0.59985308]) > > > Then, I don't know what is '[: ' below: > vs_A = w_A[:, None] * xs > > > I don't find the answer after searching around > Could you explain above code to me? > Thanks, You probably want to search for 'slice/slicing' and 'indexing' I get this http://docs.scipy.org/doc/numpy-1.10.0/reference/arrays.indexing.html [Note: I dont know much about this] -- https://mail.python.org/mailman/listinfo/python-list
Re: Trailing zeros of 100!
Am 02.01.2016 um 12:49 schrieb katye2...@gmail.com: I'm trying to write a python program to find how many trailing zeros are in 100! (factorial of 100). I used factorial from the math module, but my efforts to continue failed. Please help. Using not Python, but math: Every "0" at the end of 100! represents a multiplication by the factor 10 or the factors 2 and 5. There are 20 numbers with at least one factor 5. There are 4 numbers with at least two factors 5 (=25). There are no numbers with three factors 5 (=125). There are 50 numbers with at least one factor 2. So 100! contains 24 factors 5 and even more factors 2. So 100! contains 24 facotrs 10 and therefore has 24 trailing zeros. -- Robin Koch -- https://mail.python.org/mailman/listinfo/python-list
Re: Trailing zeros of 100!
Am 02.01.2016 um 14:14 schrieb yehudak .: Thank you so much, but... All that is Chinese for me. Can you show a 'normal' Python code for me? How about: >>> from math import log >>> sum([int(0.2**k*n) for k in range(1, int(log(n, 5))+1)]) }:-) (That implements my procedure in my other answer.) -- Robin Koch -- https://mail.python.org/mailman/listinfo/python-list
Re: We will be moving to GitHub
On 2016-01-02 17:43, Steven D'Aprano wrote: > Oh, and talking about DVCS: > > https://bitquabit.com/post/unorthodocs-abandon-your-dvcs-and-return-to-sanity/ The arguments there are pretty weak. Not working offline? I use that *ALL* *THE* *TIME*. Maybe the author lives some place where the main internet connection doesn't go down for a week because some dim bulb at AT&T disconnected the wrong cable and failed to log the fact. Maybe the author is willing to shell out highway-robbery prices for wifi on an airplane just to access repo history. Maybe the author has an unlimited data plan and good coverage. But for me, disconnected usage (along with the much easier/smarter branching & merging) is one of the indispensable features. Just because the author doesn't use a feature, doesn't mean it's useful. Consider the author's case for storing large binary blobs in a VCS and then not wanting to check out the entire repo. However, to use/tweak the logic & phrasing of the article, "Let me tell you something. Of all the time I have ever used DVCSes, over the last 15 years if we count dropping large binary files in a shared folder and eight or so if you don’t, I have wanted to store large binary files in the repository a grand total of maybe about zero times. And this is merely going down over time as CPU, memory, and storage capacity ever increases. If you work as a CGI animator/artist, or produce audio, or don't know what you're doing because you're storing generated output, then okay, sure, this is a huge feature for you. But for the rest of us, I am going to assert that this is not the use case you need to optimize for when choosing a VCS." So while I don't really have dog in the fight of git-vs-hg-vs-bzr-vs-fossil or the GitHub-vs-Bitbucket-vs-GitLab-vs-privately-hosted fight, I find the logic of that article as strained as when I first read it. -tkc -- https://mail.python.org/mailman/listinfo/python-list
Re: Trailing zeros of 100!
On 2016-01-02 03:49, katye2...@gmail.com wrote: > I'm trying to write a python program to find how many trailing > zeros are in 100! (factorial of 100). I used factorial from the > math module, but my efforts to continue failed. Please help. Pretty easy to do with strings: from math import factorial n = factorial(100) s = str(n) print(len(s) - len(s.rstrip('0'))) or count them: from itertools import takewhile sum(1 for _ in takewhile(lambda c: c == '0', reversed(s))) or mathematically: sum(1 for _ in itertools.takewhile( lambda x: n % (10**x) == 0, itertools.count(1))) -tkc -- https://mail.python.org/mailman/listinfo/python-list
Re: Trailing zeros of 100!
On 02/01/16 16:57, Robin Koch wrote: > sum([int(0.2**k*n) for k in range(1, int(log(n, 5))+1)]) But did you actually test it? -- Tony van der Hoff | mailto:t...@vanderhoff.org Ariège, France | -- https://mail.python.org/mailman/listinfo/python-list
Re: Trailing zeros of 100!
Am 02.01.2016 um 17:09 schrieb Tony van der Hoff: On 02/01/16 16:57, Robin Koch wrote: sum([int(0.2**k*n) for k in range(1, int(log(n, 5))+1)]) But did you actually test it? Yes, should work for n >= 1. Why do you ask? -- Robin Koch -- https://mail.python.org/mailman/listinfo/python-list
Re: Trailing zeros of 100!
Robin Koch wrote: > Am 02.01.2016 um 12:49 schrieb katye2...@gmail.com: > >> I'm trying to write a python program to find how many trailing zeros >> are in 100! (factorial of 100). I used factorial from the math >> module, but my efforts to continue failed. Please help. > > Using not Python, but math: > > Every "0" at the end of 100! represents a multiplication by the factor > 10 or the factors 2 and 5. > > There are 20 numbers with at least one factor 5. > There are 4 numbers with at least two factors 5 (=25). > There are no numbers with three factors 5 (=125). > > There are 50 numbers with at least one factor 2. > > So 100! contains 24 factors 5 and even more factors 2. > So 100! contains 24 facotrs 10 and therefore has 24 trailing zeros. Spelt in Python: >>> def trailing_zeros_fact(n): ... total = 0 ... while n: ... n //= 5 ... total += n ... return total ... >>> trailing_zeros_fact(100) 24 >>> trailing_zeros_fact(math.factorial(100)) 23331553860986038170424809714066675122678992066095405367148240973804383074789022353659940391295715634244802068059395627963027292159901 -- https://mail.python.org/mailman/listinfo/python-list
Re: Trailing zeros of 100!
On Sat, Jan 2, 2016 at 2:56 PM, Robin Koch wrote: > > Yes, should work for n >= 1. > The first power of 10 for which it fails in my machine is 10 ^ 17, which is not that much for modern computers. Discrete math should not meet floating points. I would post the "canonical" solution here if Peter Otten hadn't just posted it. You can use Wolfram Alpha - or Otten's solution - to see that your solution fails for inputs equal to and larger than 10^17 (there likely is a lower bound, but I won't do binary search to find it). -- Bernardo Sulzbach -- https://mail.python.org/mailman/listinfo/python-list
Re: Trailing zeros of 100!
vbr, I tried using .pop() but could not get what I wanted .Also, I can't see an advantage in reversing the number. Would you care to write explicitly the program for me (and probably for other too)? Brute Force is the style I'm thinking about. Sorry, but I learn most from viewing the code. Appreciated, Yehuda On Sat, Jan 2, 2016 at 5:24 PM, Vlastimil Brom wrote: > 2016-01-02 14:14 GMT+01:00 yehudak . : > > Vlastimil, > > Thank you so much, but... > > All that is Chinese for me. > > Can you show a 'normal' Python code for me? > > > > Yehuda > > > > On Sat, Jan 2, 2016 at 2:44 PM, Vlastimil Brom > > > wrote: > >> > >> 2016-01-02 12:49 GMT+01:00 : > >> > Hi, newbie here! > >> > I'm trying to write a python program to find how many trailing zeros > are > >> > in 100! (factorial of 100). > >> > I used factorial from the math module, but my efforts to continue > >> > failed. Please help. > >> > > >> > Thank you, > >> > Yehuda > >> > -- > >> > https://mail.python.org/mailman/listinfo/python-list > >> > >> Hi, > >> rather an illustration of the available tools in python, than a > >> (submittable) solution: > >> > >> >>> import re, math > >> >>> len(re.search(r"0*$", str(math.factorial(100))).group()) > >> 24 > >> [or the same code on more lines with some indentation - if it is > >> preserved via e-mail] > >> >>> len( > >> ... re.search( > >> ... r"0*$", > >> ... str( > >> ... math.factorial(100) > >> ... ) > >> ... ).group() > >> ... ) > >> 24 > >> >>> > >> > >> I.e. You need the length of the string resulting as the match of the > >> regular expression search for a pattern representing zero or more "0" > >> at the end of the input text, which is the string version of 100! > >> > >> Of course, there are other ways to get this result :-) > >> > >> regards, > >> vbr > > > > > Hi, > If you eventually have this as an assignment or other kind of > (self)learning task, you would want to approach this with the methods > you know, or are supposed to use. > For the math context, you may find this explanations useful: > http://www.purplemath.com/modules/factzero.htm > a rather straightforward python implementation of this seems to be > e.g. this recipe: > > http://code.activestate.com/recipes/577844-calculate-trailing-zeroes-in-a-factorial/ > Note, that you don't need to calculate the value of the factorial > itself using this way. > If you have problems with following or understanding the code, you may > show your own attempts and tell what problems you encounter with your > approach. > > My previous code sample is based on another - "brute-force" approach, > the factorial is calculated (e.g. via the math module as you have > found), then the integer is converted to a string, afterwards the part > of the result consisting only of zeros - at the end of the string is > matched with a regular expression and finally the length of it is > determined. > > Regular expressions might be handy, but are not necesarilly elementary > stuff for a newcomer in python programming. > You can count the trailing zeros in other ways too - as was suggested > - you can reverse the string and count from the beginning then, > stopping before the first non-zero digit. > The most straightforward way could be to loop (characterwise) through > the (reversed) string, check each character whether it equals to "0" > and stop as soon as there is another digit. > > hth, >vbr > -- https://mail.python.org/mailman/listinfo/python-list
Re: Trailing zeros of 100!
On 02/01/2016 17:34, yehudak . wrote: vbr, I tried using .pop() but could not get what I wanted .Also, I can't see an advantage in reversing the number. Would you care to write explicitly the program for me (and probably for other too)? Brute Force is the style I'm thinking about. Sorry, but I learn most from viewing the code. Appreciated, Yehuda On Sat, Jan 2, 2016 at 5:24 PM, Vlastimil Brom wrote: 2016-01-02 14:14 GMT+01:00 yehudak . : Vlastimil, Thank you so much, but... All that is Chinese for me. Can you show a 'normal' Python code for me? Yehuda On Sat, Jan 2, 2016 at 2:44 PM, Vlastimil Brom 2016-01-02 12:49 GMT+01:00 : Hi, newbie here! I'm trying to write a python program to find how many trailing zeros are in 100! (factorial of 100). I used factorial from the math module, but my efforts to continue failed. Please help. Thank you, Yehuda -- https://mail.python.org/mailman/listinfo/python-list Hi, rather an illustration of the available tools in python, than a (submittable) solution: import re, math len(re.search(r"0*$", str(math.factorial(100))).group()) 24 [or the same code on more lines with some indentation - if it is preserved via e-mail] len( ... re.search( ... r"0*$", ... str( ... math.factorial(100) ... ) ... ).group() ... ) 24 I.e. You need the length of the string resulting as the match of the regular expression search for a pattern representing zero or more "0" at the end of the input text, which is the string version of 100! Of course, there are other ways to get this result :-) regards, vbr Hi, If you eventually have this as an assignment or other kind of (self)learning task, you would want to approach this with the methods you know, or are supposed to use. For the math context, you may find this explanations useful: http://www.purplemath.com/modules/factzero.htm a rather straightforward python implementation of this seems to be e.g. this recipe: http://code.activestate.com/recipes/577844-calculate-trailing-zeroes-in-a-factorial/ Note, that you don't need to calculate the value of the factorial itself using this way. If you have problems with following or understanding the code, you may show your own attempts and tell what problems you encounter with your approach. My previous code sample is based on another - "brute-force" approach, the factorial is calculated (e.g. via the math module as you have found), then the integer is converted to a string, afterwards the part of the result consisting only of zeros - at the end of the string is matched with a regular expression and finally the length of it is determined. Regular expressions might be handy, but are not necesarilly elementary stuff for a newcomer in python programming. You can count the trailing zeros in other ways too - as was suggested - you can reverse the string and count from the beginning then, stopping before the first non-zero digit. The most straightforward way could be to loop (characterwise) through the (reversed) string, check each character whether it equals to "0" and stop as soon as there is another digit. hth, vbr You'll learn far more if you try writing code and then get help if it doesn't work, rather than get other people to write the code for you. Please don't top post, it's extremely annoying when trying to follow long threads. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Trailing zeros of 100!
On 02.01.16 18:33, Tim Chase wrote: or mathematically: sum(1 for _ in itertools.takewhile( lambda x: n % (10**x) == 0, itertools.count(1))) The mathematician would prove that the result is not larger than 100/4. -- https://mail.python.org/mailman/listinfo/python-list
Re: Trailing zeros of 100!
2016-01-02 18:34 GMT+01:00 yehudak . : [partly edited for bottom posting] > On Sat, Jan 2, 2016 at 5:24 PM, Vlastimil Brom > wrote: >> >> 2016-01-02 14:14 GMT+01:00 yehudak . : >> > [...]>> > On Sat, Jan 2, 2016 at 2:44 PM, Vlastimil Brom >> > >> > wrote: >> >> >> >> 2016-01-02 12:49 GMT+01:00 : >> >> > Hi, newbie here! >> >> > I'm trying to write a python program to find how many trailing zeros >> >> > are >> >> > in 100! (factorial of 100). >> >> > I used factorial from the math module, but my efforts to continue >> >> > failed. Please help. >> >> > >> >> > Thank you, >> >> > Yehuda >> >> > -- >> >> > https://mail.python.org/mailman/listinfo/python-list >> >> >> > [...] >> > >> Hi, >> If you eventually have this as an assignment or other kind of >> (self)learning task, you would want to approach this with the methods >> you know, or are supposed to use. >> For the math context, you may find this explanations useful: >> http://www.purplemath.com/modules/factzero.htm >> a rather straightforward python implementation of this seems to be >> e.g. this recipe: >> >> http://code.activestate.com/recipes/577844-calculate-trailing-zeroes-in-a-factorial/ >> Note, that you don't need to calculate the value of the factorial >> itself using this way. >> If you have problems with following or understanding the code, you may >> show your own attempts and tell what problems you encounter with your >> approach. >> >> My previous code sample is based on another - "brute-force" approach, >> the factorial is calculated (e.g. via the math module as you have >> found), then the integer is converted to a string, afterwards the part >> of the result consisting only of zeros - at the end of the string is >> matched with a regular expression and finally the length of it is >> determined. >> >> Regular expressions might be handy, but are not necesarilly elementary >> stuff for a newcomer in python programming. >> You can count the trailing zeros in other ways too - as was suggested >> - you can reverse the string and count from the beginning then, >> stopping before the first non-zero digit. >> The most straightforward way could be to loop (characterwise) through >> the (reversed) string, check each character whether it equals to "0" >> and stop as soon as there is another digit. >> >> hth, >>vbr > > > vbr, > I tried using .pop() but could not get what I wanted .Also, I can't see an > advantage in reversing the number. > Would you care to write explicitly the program for me (and probably for > other too)? > Brute Force is the style I'm thinking about. > > Sorry, but I learn most from viewing the code. > > Appreciated, > Yehuda > Hi, reversing the string would be useful for directly looping over the string (the interesting zeros would be at the beginning of the reversed string. If you use pop() on a list of the digits, the items are taken from the end of the list by default, hence no reversing is needed. What problems do you have with this route? (you will need to convert from the integer result to string, then to list and use pop() and count the steps until you reach a non-zero digit) If you need this kind of soulution (computing the factorial, converting to string, counting the trailing zero digits), I believe, the most easily comprehensible version was posted by Tim Chase a bit earlier. In the interactive interpreter, with some intermediate steps added, it can look like this: >>> from math import factorial >>> fact100_int = factorial(100) >>> fact100_string = str(fact100_int) >>> fact100_string_without_trailing_zeros = fact100_string.rstrip("0") >>> len(fact100_string) - len(fact100_string_without_trailing_zeros) 24 >>> [aditional info on the rstrip method of any string ("abcd" used for illustration here): ] >>> print("abcd".rstrip.__doc__) S.rstrip([chars]) -> str Return a copy of the string S with trailing whitespace removed. If chars is given and not None, remove characters in chars instead. >>> It should be noted that the approaches which involve computing of the factorial itself have much lower limits on the size compared to the algorithmic ones, but for the given case both are sufficient. hth, vbr -- https://mail.python.org/mailman/listinfo/python-list
Re: subprocess check_output
Turns out it wasn't running against the server I thought it was. Apologies for the spam. -carlos On Wed, Dec 30, 2015 at 11:02 PM Cameron Simpson wrote: > On 30Dec2015 21:14, Carlos Barera wrote: > >Trying to run a specific command (ibstat) installed in /usr/sbin on an > >Ubuntu 15.04 machine, using subprocess.check_output and getting "/bin/sh: > >/usr/sbin/ibstat: No such file or directory" > > > >I tried the following: > >- running the command providing full path > >- running with executable=bash > >- running with (['/bin/bash', '-c' , "/usr/sbin/ibstat"]) > > > >Nothing worked ... > > The first check is to run the command from a shell. Does it work? Does > "which > ibstat" confirm that the command exist at that path? Is it even installed? > > If it does, you should be able to run it directly without using a shell: > > subprocess.call(['/usr/sbin/ibstat'], ...) > > or just plain ['ibstat']. Also remember that using "sh -c blah" or "bash -c > blah" is subject to all the same security issues that subprocess' > "shell=True" > parameter is, and that it should be avoided without special reason. > > Finally, remember to drop the common Linux fetish with "bash". Just use > "sh"; > on many systems it _is_ bash, but it will provide portable use. The bash is > just a partiular Bourne style shell, not installed everywhere, and rarely > of > any special benefit for scripts over the system /bin/sh (which _every_ UNIX > system has). > > If none of this solves your problem, please reply including the failing > code > and a transcript of the failure output. > > Thanks, > Cameron Simpson > -- https://mail.python.org/mailman/listinfo/python-list
Re: Trailing zeros of 100!
Hello vbr, That's EXACTLY what I needed. rstrip is new for me so I'm going to Dr. Google to learn. On my efforts I was struggling with .pop() but wasn't very successful... Thank you so much, Yehuda On Sat, Jan 2, 2016 at 8:29 PM, Vlastimil Brom wrote: > 2016-01-02 18:34 GMT+01:00 yehudak . : > [partly edited for bottom posting] > > On Sat, Jan 2, 2016 at 5:24 PM, Vlastimil Brom > > > wrote: > >> > >> 2016-01-02 14:14 GMT+01:00 yehudak . : > >> > > [...]>> > On Sat, Jan 2, 2016 at 2:44 PM, Vlastimil Brom > >> > > >> > wrote: > >> >> > >> >> 2016-01-02 12:49 GMT+01:00 : > >> >> > Hi, newbie here! > >> >> > I'm trying to write a python program to find how many trailing > zeros > >> >> > are > >> >> > in 100! (factorial of 100). > >> >> > I used factorial from the math module, but my efforts to continue > >> >> > failed. Please help. > >> >> > > >> >> > Thank you, > >> >> > Yehuda > >> >> > -- > >> >> > https://mail.python.org/mailman/listinfo/python-list > >> >> > >> > [...] > >> > > >> Hi, > >> If you eventually have this as an assignment or other kind of > >> (self)learning task, you would want to approach this with the methods > >> you know, or are supposed to use. > >> For the math context, you may find this explanations useful: > >> http://www.purplemath.com/modules/factzero.htm > >> a rather straightforward python implementation of this seems to be > >> e.g. this recipe: > >> > >> > http://code.activestate.com/recipes/577844-calculate-trailing-zeroes-in-a-factorial/ > >> Note, that you don't need to calculate the value of the factorial > >> itself using this way. > >> If you have problems with following or understanding the code, you may > >> show your own attempts and tell what problems you encounter with your > >> approach. > >> > >> My previous code sample is based on another - "brute-force" approach, > >> the factorial is calculated (e.g. via the math module as you have > >> found), then the integer is converted to a string, afterwards the part > >> of the result consisting only of zeros - at the end of the string is > >> matched with a regular expression and finally the length of it is > >> determined. > >> > >> Regular expressions might be handy, but are not necesarilly elementary > >> stuff for a newcomer in python programming. > >> You can count the trailing zeros in other ways too - as was suggested > >> - you can reverse the string and count from the beginning then, > >> stopping before the first non-zero digit. > >> The most straightforward way could be to loop (characterwise) through > >> the (reversed) string, check each character whether it equals to "0" > >> and stop as soon as there is another digit. > >> > >> hth, > >>vbr > > > > > > vbr, > > I tried using .pop() but could not get what I wanted .Also, I can't see > an > > advantage in reversing the number. > > Would you care to write explicitly the program for me (and probably for > > other too)? > > Brute Force is the style I'm thinking about. > > > > Sorry, but I learn most from viewing the code. > > > > Appreciated, > > Yehuda > > > Hi, > reversing the string would be useful for directly looping over the > string (the interesting zeros would be at the beginning of the > reversed string. > If you use pop() on a list of the digits, the items are taken from the > end of the list by default, hence no reversing is needed. > What problems do you have with this route? (you will need to convert > from the integer result to string, then to list and use pop() and > count the steps until you reach a non-zero digit) > > If you need this kind of soulution (computing the factorial, > converting to string, counting the trailing zero digits), I believe, > the most easily comprehensible version was posted by Tim Chase a bit > earlier. > In the interactive interpreter, with some intermediate steps added, it > can look like this: > > >>> from math import factorial > >>> fact100_int = factorial(100) > >>> fact100_string = str(fact100_int) > >>> fact100_string_without_trailing_zeros = fact100_string.rstrip("0") > >>> len(fact100_string) - len(fact100_string_without_trailing_zeros) > 24 > >>> > > [aditional info on the rstrip method of any string ("abcd" used for > illustration here): ] > >>> print("abcd".rstrip.__doc__) > S.rstrip([chars]) -> str > > Return a copy of the string S with trailing whitespace removed. > If chars is given and not None, remove characters in chars instead. > >>> > > It should be noted that the approaches which involve computing of the > factorial itself have much lower limits on the size compared to the > algorithmic ones, but for the given case both are sufficient. > > hth, > vbr > -- https://mail.python.org/mailman/listinfo/python-list
Re: Trailing zeros of 100!
Hi again, I looked a little deeper at your code. Smart solution and kudos. Yehuda On Sat, Jan 2, 2016 at 10:02 PM, yehudak . wrote: > Hello vbr, > That's EXACTLY what I needed. rstrip is new for me so I'm going to Dr. > Google to learn. > > On my efforts I was struggling with .pop() but wasn't very successful... > > Thank you so much, > Yehuda > > On Sat, Jan 2, 2016 at 8:29 PM, Vlastimil Brom > wrote: > >> 2016-01-02 18:34 GMT+01:00 yehudak . : >> [partly edited for bottom posting] >> > On Sat, Jan 2, 2016 at 5:24 PM, Vlastimil Brom < >> vlastimil.b...@gmail.com> >> > wrote: >> >> >> >> 2016-01-02 14:14 GMT+01:00 yehudak . : >> >> > >> [...]>> > On Sat, Jan 2, 2016 at 2:44 PM, Vlastimil Brom >> >> > >> >> > wrote: >> >> >> >> >> >> 2016-01-02 12:49 GMT+01:00 : >> >> >> > Hi, newbie here! >> >> >> > I'm trying to write a python program to find how many trailing >> zeros >> >> >> > are >> >> >> > in 100! (factorial of 100). >> >> >> > I used factorial from the math module, but my efforts to continue >> >> >> > failed. Please help. >> >> >> > >> >> >> > Thank you, >> >> >> > Yehuda >> >> >> > -- >> >> >> > https://mail.python.org/mailman/listinfo/python-list >> >> >> >> >> > [...] >> >> > >> >> Hi, >> >> If you eventually have this as an assignment or other kind of >> >> (self)learning task, you would want to approach this with the methods >> >> you know, or are supposed to use. >> >> For the math context, you may find this explanations useful: >> >> http://www.purplemath.com/modules/factzero.htm >> >> a rather straightforward python implementation of this seems to be >> >> e.g. this recipe: >> >> >> >> >> http://code.activestate.com/recipes/577844-calculate-trailing-zeroes-in-a-factorial/ >> >> Note, that you don't need to calculate the value of the factorial >> >> itself using this way. >> >> If you have problems with following or understanding the code, you may >> >> show your own attempts and tell what problems you encounter with your >> >> approach. >> >> >> >> My previous code sample is based on another - "brute-force" approach, >> >> the factorial is calculated (e.g. via the math module as you have >> >> found), then the integer is converted to a string, afterwards the part >> >> of the result consisting only of zeros - at the end of the string is >> >> matched with a regular expression and finally the length of it is >> >> determined. >> >> >> >> Regular expressions might be handy, but are not necesarilly elementary >> >> stuff for a newcomer in python programming. >> >> You can count the trailing zeros in other ways too - as was suggested >> >> - you can reverse the string and count from the beginning then, >> >> stopping before the first non-zero digit. >> >> The most straightforward way could be to loop (characterwise) through >> >> the (reversed) string, check each character whether it equals to "0" >> >> and stop as soon as there is another digit. >> >> >> >> hth, >> >>vbr >> > >> > >> > vbr, >> > I tried using .pop() but could not get what I wanted .Also, I can't see >> an >> > advantage in reversing the number. >> > Would you care to write explicitly the program for me (and probably for >> > other too)? >> > Brute Force is the style I'm thinking about. >> > >> > Sorry, but I learn most from viewing the code. >> > >> > Appreciated, >> > Yehuda >> > >> Hi, >> reversing the string would be useful for directly looping over the >> string (the interesting zeros would be at the beginning of the >> reversed string. >> If you use pop() on a list of the digits, the items are taken from the >> end of the list by default, hence no reversing is needed. >> What problems do you have with this route? (you will need to convert >> from the integer result to string, then to list and use pop() and >> count the steps until you reach a non-zero digit) >> >> If you need this kind of soulution (computing the factorial, >> converting to string, counting the trailing zero digits), I believe, >> the most easily comprehensible version was posted by Tim Chase a bit >> earlier. >> In the interactive interpreter, with some intermediate steps added, it >> can look like this: >> >> >>> from math import factorial >> >>> fact100_int = factorial(100) >> >>> fact100_string = str(fact100_int) >> >>> fact100_string_without_trailing_zeros = fact100_string.rstrip("0") >> >>> len(fact100_string) - len(fact100_string_without_trailing_zeros) >> 24 >> >>> >> >> [aditional info on the rstrip method of any string ("abcd" used for >> illustration here): ] >> >>> print("abcd".rstrip.__doc__) >> S.rstrip([chars]) -> str >> >> Return a copy of the string S with trailing whitespace removed. >> If chars is given and not None, remove characters in chars instead. >> >>> >> >> It should be noted that the approaches which involve computing of the >> factorial itself have much lower limits on the size compared to the >> algorithmic ones, but for the given case both are sufficient. >> >> hth, >> vbr >> > > -- https://mail.python.org/mail
Re: Trailing zeros of 100!
On 02/01/2016 20:02, yehudak . wrote: Hello vbr, That's EXACTLY what I needed. rstrip is new for me so I'm going to Dr. Google to learn. On my efforts I was struggling with .pop() but wasn't very successful... Thank you so much, Yehuda How many times do you have to be asked to not top post? Just how thick are you? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Trailing zeros of 100!
On 02/01/2016 20:09, yehudak . wrote: Hi again, I looked a little deeper at your code. Smart solution and kudos. Yehuda Still top posting? Thanks a bunch. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Trailing zeros of 100!
On Sun, Jan 3, 2016 at 3:56 AM, Robin Koch wrote: > Am 02.01.2016 um 17:09 schrieb Tony van der Hoff: >> >> On 02/01/16 16:57, Robin Koch wrote: >>> >>> sum([int(0.2**k*n) for k in range(1, int(log(n, 5))+1)]) >> >> >> But did you actually test it? > > > Yes, should work for n >= 1. > > Why do you ask? Your "should work" does not sound good as a response to "actually test". Normally I would expect the response to be "Yes, and it worked for me" (maybe with a log of an interactive session). Floating point can't represent every integer, and above 2**53 you end up able to represent only those which are multiples of ever-increasing powers of two; 100! is between 2**524 and 2**525, so any float operations are going to be rounding off to the nearest 2**471 or thereabouts. That's... a lot of rounding. That's like trying to calculate whether pi is rational, but basing your calculations on the approximation 3.14. :) ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: subprocess check_output
On Sun, Jan 3, 2016 at 7:39 AM, Carlos Barera wrote: > Turns out it wasn't running against the server I thought it was. > Apologies for the spam. Heh. No problem. That's part of why I suggested running it from the shell. There are two possibilities: either it also fails from the shell (in which case you've eliminated Python as the problem, and can concentrate on "why is my command not working"), or it succeeds when run manually and still fails from Python (in which case you can start investigating the differences). And every now and then, it's worth doing a stupid smoke test just to see if your changes are even having effect. You have no idea how many times a bug investigation has come down to "whoops, I forgot to save the file" or "whoops, I was in the wrong directory"... ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Trailing zeros of 100!
Mark Lawrence wrote: > Please don't top post, it's extremely annoying when trying to follow > long threads. As are full quotes. -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail. -- https://mail.python.org/mailman/listinfo/python-list
Re: Trailing zeros of 100!
Am 02.01.2016 um 22:57 schrieb Chris Angelico: On Sun, Jan 3, 2016 at 3:56 AM, Robin Koch wrote: Am 02.01.2016 um 17:09 schrieb Tony van der Hoff: On 02/01/16 16:57, Robin Koch wrote: sum([int(0.2**k*n) for k in range(1, int(log(n, 5))+1)]) But did you actually test it? Yes, should work for n >= 1. Why do you ask? Your "should work" does not sound good as a response to "actually test". Normally I would expect the response to be "Yes, and it worked for me" (maybe with a log of an interactive session). Well, honestly, I trusted my math and didn't thought much about the technical limitations. I only tried values from 1 to 100 and then again 12345, I believe, to test the algorithm. > Floating point can't represent every integer, and above 2**53 you end up able to represent only those which are multiples of ever-increasing powers of two; 100! is between 2**524 and 2**525, so any float operations are going to be rounding off to the nearest 2**471 or thereabouts. That's... a lot of rounding. That's like trying to calculate whether pi is rational, but basing your calculations on the approximation 3.14. :) When I find more time I take a closer look at it. Thank you (and Bernardo) for your clarification. I hope everyone who read my article reads yours, too and learns from it. ;-) -- Robin Koch -- https://mail.python.org/mailman/listinfo/python-list
Re: Trailing zeros of 100!
Robin Koch writes: > Am 02.01.2016 um 22:57 schrieb Chris Angelico: > >>> But did you actually test it? > >> > >> Yes, should work for n >= 1. By “test it”, Chris of course means test it *by implementing it in a program and running that program in Python*. > >> Why do you ask? > > > > Your "should work" does not sound good as a response to "actually > > test". Normally I would expect the response to be "Yes, and it > > worked for me" (maybe with a log of an interactive session). > > Well, honestly, I trusted my math and didn't thought much about the > technical limitations. That's why it's good to actually test the hypothesis in a real computer program, run on the actual computer system you're going to use. Computers are physical systems, with technical compromises to the physical constraints under which they were built. They are not perfect implementations of our ideal mathematics, and testing the mathematics is no guarantee the mathematical assumptions will survive your program unscathed. So, a request “Did you actually test it?” is both a polite reminder to do that, and an attempt to get you to do so if you didn't. If you didn't, then answering “yes” is wasting everyone's time. -- \ “As the most participatory form of mass speech yet developed, | `\the Internet deserves the highest protection from governmental | _o__) intrusion.” —U.S. District Court Judge Dalzell | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list
Re: We will be moving to GitHub
Chris Angelico : > On Sun, Jan 3, 2016 at 1:52 AM, Marko Rauhamaa wrote: >> Terminology aside, if I do this with Git: >> >>-++> >> \ ^ >> \pull /push >>v / >>+--+ >> edit >> >> everything goes in without any further ado. >> >> However, this operation will be blocked by Git: >> >> >>--+--+++---> >> \ \ ^X >>\ \pull /push/ >> \ v // >> pull\ +--+/push >> \ edit / >>v / >>+-+ >> >> Not so by Teamware as long as the pushes don't have files in common. > > Ah, I see what you mean. > > That's a constantly-debated point, and it's actually possible to make > git accept this, although it's not a normal workflow. Instead, you > just 'git pull' (possibly with --rebase) before you 'git push'. You > either create a new merge commit, or make it very clear that you are > changing your commits to pretend they were committed after the > already-pushed ones. Or you do a force-push and discard the other > commits (this is correct if you amended a commit). You HAVE to choose > because these are three viable solutions, and only a human can make > the decision. > > Teamware presumably picked one of them, Teamware didn't have to pick any of them since Teamware's commits were done per individual files. The repository didn't have a commit history. Thus, Teamware was equivalent to Hg/Git with each file treated as an independent repository. Marko -- https://mail.python.org/mailman/listinfo/python-list
Re: We will be moving to GitHub
On 01/01/2016 19:39, Mark Lawrence wrote: Please see https://mail.python.org/pipermail/core-workflow/2016-January/000345.html This should encourage developers at all levels to help out, such that the list of open issues on the bug tracker falls drastically. One thing that I forgot is that if nobody responds to something on the bug tracker, then nothing happens. As I write there are 516 issues with only one message. Obviously some can be discarded as e.g. they are place holders for core devs, but it certainly leaves a large number that give the OP the impression that they are an irrelevance. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: We will be moving to GitHub
On Sun, Jan 3, 2016 at 11:33 AM, Marko Rauhamaa wrote: >> That's a constantly-debated point, and it's actually possible to make >> git accept this, although it's not a normal workflow. Instead, you >> just 'git pull' (possibly with --rebase) before you 'git push'. You >> either create a new merge commit, or make it very clear that you are >> changing your commits to pretend they were committed after the >> already-pushed ones. Or you do a force-push and discard the other >> commits (this is correct if you amended a commit). You HAVE to choose >> because these are three viable solutions, and only a human can make >> the decision. >> >> Teamware presumably picked one of them, > > Teamware didn't have to pick any of them since Teamware's commits were > done per individual files. The repository didn't have a commit history. > > Thus, Teamware was equivalent to Hg/Git with each file treated as an > independent repository. And what if you and someone else edit different parts of the same file? How is that handled? Why should the top and bottom of one file be dramatically different from two separate files? ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: We will be moving to GitHub
Chris Angelico : > On Sun, Jan 3, 2016 at 11:33 AM, Marko Rauhamaa wrote: >> Teamware didn't have to pick any of them since Teamware's commits >> were done per individual files. The repository didn't have a commit >> history. >> >> Thus, Teamware was equivalent to Hg/Git with each file treated as an >> independent repository. > > And what if you and someone else edit different parts of the same > file? How is that handled? Why should the top and bottom of one file > be dramatically different from two separate files? Files are a natural unit of granularity; that's why we don't place all source code in a single source code file. There are exceptions, but in general I'd say only one person should be editing one file at any given time. As I mentioned before, Darcs tries to eat the cake and have it, too. It provides Git-like repository semantics and a clearly defined concept of parallel changes. It does *not* make a distinction between two files and two parts of a file. Unfortunately, rumor has it that Darcs can run into serious performance issues as it enforces the conceptual purity. That's why I think Teamware's file-level focus is the practical sweet spot of distributed version control. Marko -- https://mail.python.org/mailman/listinfo/python-list
Re: (Execution) Termination bit, Alternation bit.
"Chris Angelico" wrote in message news:mailman.64.1451433611.11925.python-l...@python.org... On Wed, Dec 30, 2015 at 8:43 AM, Skybuck Flying wrote: Not at all, these assembler statements can be replaced with python statements and then you have the exact same problem ! ;) " Then do so. Give us an example where this problem occurs in pure Python. " I basically already did... The while loops and calls themselfes already enough of a burdon... Should be easy to turn that somewhat pseudo code into python code ! :) Bye, Skybuck. -- https://mail.python.org/mailman/listinfo/python-list
Re: Trailing zeros of 100!
let's put an end to this. from math import log # simple one to understand. complexity: O(n*log(n)) def countzeros_va(n): count = 0 for x in xrange(1, n + 1): while x % 5 == 0: count += 1 x //= 5 return count # better approach. complexity: O(log(n)) def countzeros_vb(n): count, c5 = 0, 5 while c5 <= n: count += (n // c5) c5 *= 5 return count # this is same as before, its just that while loops irk me def countzeros_vc(n): return sum(n // (5**x) for x in range(1, int(log(n, 5) + 3))) # adding +3 to be sure. never trust approximations. def run_sample_tests(): precal = {3: 0, 60: 14, 100: 24, 1024: 253, 23456: 5861, 8735373: 2183837} for x in precal: assert precal[x] == countzeros_va(x) == countzeros_vb(x) == countzeros_vc(x) if __name__ == '__main__': run_sample_tests() Although the code is deterministic, it can be further tested from http://www.wolframalpha.com/widgets/view.jsp?id=54da27e6e09dc404890a578735b9f7d8 http://www.spoj.com/problems/FCTRL/ On Jan 2, 2016 5:22 PM, wrote: > > Hi, newbie here! > I'm trying to write a python program to find how many trailing zeros are in > 100! (factorial of 100). > I used factorial from the math module, but my efforts to continue failed. > Please help. > > Thank you, > Yehuda > -- > https://mail.python.org/mailman/listinfo/python-list On Sun, Jan 3, 2016 at 5:50 AM, Ben Finney wrote: > Robin Koch writes: > >> Am 02.01.2016 um 22:57 schrieb Chris Angelico: >> >>> But did you actually test it? >> >> >> >> Yes, should work for n >= 1. > > By “test it”, Chris of course means test it *by implementing it in a > program and running that program in Python*. > >> >> Why do you ask? >> > >> > Your "should work" does not sound good as a response to "actually >> > test". Normally I would expect the response to be "Yes, and it >> > worked for me" (maybe with a log of an interactive session). >> >> Well, honestly, I trusted my math and didn't thought much about the >> technical limitations. > > That's why it's good to actually test the hypothesis in a real computer > program, run on the actual computer system you're going to use. > > Computers are physical systems, with technical compromises to the > physical constraints under which they were built. > > They are not perfect implementations of our ideal mathematics, and > testing the mathematics is no guarantee the mathematical assumptions > will survive your program unscathed. > > So, a request “Did you actually test it?” is both a polite reminder to > do that, and an attempt to get you to do so if you didn't. > > If you didn't, then answering “yes” is wasting everyone's time. > > -- > \ “As the most participatory form of mass speech yet developed, | > `\the Internet deserves the highest protection from governmental | > _o__) intrusion.” —U.S. District Court Judge Dalzell | > Ben Finney > > -- > https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: We will be moving to GitHub
On 01/02/2016 12:02 AM, Ben Finney wrote: > What is being done to stave off the common response, addressed by GitHub > users to people submitting a change as a link to their Git repository, > of “can you please submit that as a GitHub pull request”? > > That common response makes for an unnecessary and IMO unacceptable > pressure toward centralisation. GitHub's “pull request” workflow is > entirely proprietary and can only be done within GitHub. Really? This seems like an entirely artificial github requirement. There's absolutely no reason why github couldn't do a pull request from any arbitrary, valid git url. -- https://mail.python.org/mailman/listinfo/python-list
Re: We will be moving to GitHub
On 01/01/2016 11:43 PM, Steven D'Aprano wrote: > On Sat, 2 Jan 2016 07:09 am, Chris Angelico wrote: > >> Yes, git is a capable tool. But so is Mercurial, and the arguments >> weren't primarily based on differences in functionality (which are >> pretty minor). It's mainly about the network effect. > > You call it the network effect. I call it monoculture. Indeed. The whole purpose of git is to allow development to be distributed. Is it a matter of hosting space? Is it too expensive for python.org to host their own public-facing git repository? Especially if python.org has no plans to use github's issue tracker this move makes little sense to me. A pull request can be made from any developer's own git repository without github, or even from github if other developers really want to work there. I can understand why OSS projects like github given its complete project-management options. But if it's just the repository you're after, I get far more mileage from my own locally-hosted git repositories. It's not at all hard to push to a read-only public http git repository. Pull requests can be made against individual developers' http repos or hosted git providers. -- https://mail.python.org/mailman/listinfo/python-list
GitHub's “pull request” is proprietary lock-in (was: We will be moving to GitHub)
Michael Torrie writes: > On 01/02/2016 12:02 AM, Ben Finney wrote: > > GitHub's “pull request” workflow is entirely proprietary and can > > only be done within GitHub. > > Really? This seems like an entirely artificial github requirement. Yes, it is. > There's absolutely no reason why github couldn't do a pull request from > any arbitrary, valid git url. Right. The proprietary GitHub “pull request” has many more features (including a code review tool and discussion thread that are automatically tied to the pull request) which make it attractive. The fact these features (unlike Git) are wholly proprietary, and the valuable processes and data they generate cannot be exported and continued easily in another instance when a community chooses, are what makes GitHub's “pull request” an attractive nuisance. That and other vendor-locked workflow aspects of GitHub makes it a poor choice for communities that want to retain the option of control over their processes and data. -- \ “Try adding “as long as you don't breach the terms of service – | `\ according to our sole judgement” to the end of any cloud | _o__) computing pitch.” —Simon Phipps, 2010-12-11 | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list
installing python 2.7.11 + win32 on win 10
the install of the basic 2.7 seems to go ok but when installing the win32 extensions, I get: close failed in file object destructor: sys.excepthook is missing lost sys.stderr I've tried installing as administrator but no joy. what should I try next? -- https://mail.python.org/mailman/listinfo/python-list
Re: GitHub's ³pull request² is proprietary lock-in
Michael Vilain writes: > We used stash/bitbucket at my last contract. It's the second site I've > come across that used Atlasian's toolset. Yes, I know it's not > statistically significant. > > Anyway, the pull/merge request workflow is becoming pretty standard. I think you're missing a distinction between "pull/merge request workflow" and the specific artifact that github _calls_ a "pull request", which includes references to specific github accounts, a discussion thread on their proprietary discussion software (vs an email list or the python issue tracker) maintained on their servers and not servers that PSF controls, etc. -- https://mail.python.org/mailman/listinfo/python-list
Re: GitHub's ³pull request² is proprietary lock-in
Am 03.01.16 um 08:04 schrieb Random832: Michael Vilain writes: We used stash/bitbucket at my last contract. It's the second site I've come across that used Atlasian's toolset. Yes, I know it's not statistically significant. Anyway, the pull/merge request workflow is becoming pretty standard. I think you're missing a distinction between "pull/merge request workflow" and the specific artifact that github _calls_ a "pull request", which includes references to specific github accounts, a discussion thread on their proprietary discussion software (vs an email list or the python issue tracker) maintained on their servers and not servers that PSF controls, etc. Arguably, the most valuable outcome of the pull request in the end is the patch, which is of course contained in the git repository. GitHub also sends email notifications if a pull request is edited. So if the account holder for GitHub keeps an archive of all mail from notificati...@github.com, then also the big part of this discussion is preserved. I doubt that many people want to go back to see the arguments for a certain merge; this thread will also soon be abandoned, people will know that Python lives on GitHub and live with it, move on and do something more valuable. Christian -- https://mail.python.org/mailman/listinfo/python-list