Re: Use of Python logo

2016-01-19 Thread Jussi Piitulainen
Carolina Nunez writes: > We at Chetu as Python developers would like to include the Python logo > on our website, please advise if we can do so. See here: . That's the entry titled "Python Logo" in the Community tab at the top of the python.org front page,

Re: Single format descriptor for list

2016-01-20 Thread Jussi Piitulainen
"Frank Millman" writes: > "Paul Appleby" wrote in message > news:pan.2016.01.20.09.35.09@nowhere.invalid... >> >> In BASH, I can have a single format descriptor for a list: >> >> $ a='4 5 6 7' >> $ printf "%sth\n" $a >> 4th >> 5th >> 6th >> 7th >> >> Is this not possible in Python? Using "join" r

Re: How to simulate C style integer division?

2016-01-21 Thread Jussi Piitulainen
Shiyao Ma writes: > I wanna simulate C style integer division in Python3. > > So far what I've got is: > # a, b = 3, 4 > > import math > result = float(a) / b > if result > 0: > result = math.floor(result) > else: > result = math.ceil(result) > > I found it's too laborious. Any quick way? The

Re: How to simulate C style integer division?

2016-01-21 Thread Jussi Piitulainen
Paul Rubin writes: > Ben Finney writes: >> I'm not sure I know exactly what behaviour you want (“C style” may mean >> different things to each of us). > > I thought he meant trunc-division, so -5 / 2 = -2 and -5 % 2 = -1. > Python specifies floor division but C leaves it unspecified, I thought. I

Re: How to simulate C style integer division?

2016-01-21 Thread Jussi Piitulainen
Jussi Piitulainen writes: > Shiyao Ma writes: > >> I wanna simulate C style integer division in Python3. >> >> So far what I've got is: >> # a, b = 3, 4 >> >> import math >> result = float(a) / b >> if result > 0: >> result =

Re: How to simulate C style integer division?

2016-01-21 Thread Jussi Piitulainen
Steven D'Aprano writes: > So my guess is that the fastest, and certainly the most obvious, way > to get the same integer division behaviour as C99 would be: > > def intdiv(a, b): > # C99 style integer division with truncation towards zero. > n = a//b > if (a < 0) != (b < 0): >

Re: How to simulate C style integer division?

2016-01-21 Thread Jussi Piitulainen
Marko Rauhamaa writes: > Jussi Piitulainen writes: > >> Steven D'Aprano writes: >> >>> So my guess is that the fastest, and certainly the most obvious, way >>> to get the same integer division behaviour as C99 would be: >>> >>>

Re: How to simulate C style integer division?

2016-01-23 Thread Jussi Piitulainen
Grobu writes: >> def intdiv(a, b): >> return (a - (a % (-b if a < 0 else b))) / b >> >> > > Duh ... Got confused with modulos (again). > > def intdiv(a, b): > return (a - (a % (-abs(b) if a < 0 else abs(b / b You should use // here to get an exact integer result. -- https://mail.pyt

Re: psss...I want to move from Perl to Python

2016-01-29 Thread Jussi Piitulainen
Fillmore writes: > Does Python have Regexps? Start by importing the re module (as said). Find its documentation at the following link (together with a list of many other modules that come standard with Python). Also, once imported to the interactive session, help(re), dir(re). https://docs.pytho

Re: Mimick tac with python.

2016-01-30 Thread Jussi Piitulainen
Christian Gollwitzer writes: > Am 30.01.16 um 05:58 schrieb Random832: >> On Fri, Jan 29, 2016, at 23:46, Hongyi Zhao wrote: >>> awk '{a[NR]=$0} END {while (NR) print a[NR--]}' input_file >>> perl -e 'print reverse<>' input_file >> >> Well, both of those read the whole file into memory - tac is so

Re: Set Operations on Dicts

2016-02-08 Thread Jussi Piitulainen
Marco Kaulea writes: > In one talk (I think it was [1]) it was described that sets are > basically dicts without the values. Therefor it should be easy to > apply set operations on dicts, for example: > > {'a': 123, 'b': 456} & {'a'} => {'a': 123} > {'a': 123, 'b': 456} - {'a'} => {'b': 456} > >

Re: Set Operations on Dicts

2016-02-08 Thread Jussi Piitulainen
Matt Wheeler writes: > On 8 February 2016 at 12:17, Jussi Piitulainen wrote: >> Also, what would be the nicest current way to express a priority union >> of dicts? >> >> { k:(d if k in d else e)[k] for k in d.keys() | e.keys() } > > Since Python 3.5: {**e, **d

Re: Set Operations on Dicts

2016-02-08 Thread Jussi Piitulainen
Random832 writes: > On Mon, Feb 8, 2016, at 08:32, Matt Wheeler wrote: >> On 8 February 2016 at 12:17, Jussi Piitulainen wrote: >> > Also, what would be the nicest current way to express a priority union >> > of dicts? >> > >> > { k:(d if

Re: Considering migrating to Python from Visual Basic 6 for engineering applications

2016-02-21 Thread Jussi Piitulainen
BartC writes: > On 21/02/2016 07:28, Larry Hudson wrote: >> On 02/20/2016 10:38 AM, wrong.addres...@gmail.com wrote: > >>> Or can I write my own reading subroutines which can then be called like >>> ReadVBstyle 8, ND, NIN, NT >>> to make the code more readable? > >> ABSOLUTELY!! Most Python progr

Re: Considering migrating to Python from Visual Basic 6 for engineering applications

2016-02-21 Thread Jussi Piitulainen
BartC writes: > But this is not so much to do with VB6, but with a very fundamental > capability that seems missing in modern languages. All that's missing is a minor convenience that turns out to be mainly awkward. Not at all fundamental. The capability of parsing simple input formats is easily

Re: Considering migrating to Python from Visual Basic 6 for engineering applications

2016-02-22 Thread Jussi Piitulainen
BartC writes: > On 21/02/2016 21:52, Jussi Piitulainen wrote: [...] >>>>> def istriangle(*threeintegers): >> a,b,c = sorted(threeintegers) >> return a*a + b*b == c*c > > (That detects right-angled triangles. I think 'return a+b>c

Re: Considering migrating to Python from Visual Basic 6 for engineering applications

2016-02-22 Thread Jussi Piitulainen
Steven D'Aprano writes: > On Mon, 22 Feb 2016 08:52 am, Jussi Piitulainen wrote: > >> BartC writes: > >>> IIRC, the first programming exercise I ever did (in 1976 using Algol >>> 60) involved reading 3 numbers from the teletype and working out if &g

Re: Cycling through iterables diagonally

2016-02-26 Thread Jussi Piitulainen
Pablo Lucena writes: > Hello, > > I am trying to accomplish the following: > > Say I have a group of 4 lists as follows: > > l1 = ['a1', 'a2', 'a3', 'a4'] > l2 = ['b1', 'b2', 'b3', 'b4'] > l3 = ['c1', 'c2', 'c3', 'c4'] > l4 = ['d1', 'd2', 'd3', 'd4'] > > I would like to cycle through these lists "

Re: Explaining names vs variables in Python

2016-03-02 Thread Jussi Piitulainen
Salvatore DI DIO writes: [- -] > But where is the consistency ? if I try : > v = 890 w = 890 v is w > False I think it goes as follows. Python keeps a cached pool of some numbers that may occur relatively often. When a numerical expression evaluates to a cached value, it returns

Re: Explaining names vs variables in Python

2016-03-02 Thread Jussi Piitulainen
Chris Angelico writes: > Python defines that every object has an identity, which can be > represented as an integer. Since this is an intrinsic part of the > object, no two distinct objects can truly have identical > characteristics. Python's objects are like rifles - there are many > like it, bu

Re: Explaining names vs variables in Python

2016-03-02 Thread Jussi Piitulainen
Ian Kelly writes: > On Wed, Mar 2, 2016 at 2:35 AM, Jussi Piitulainen wrote: >> The following are too delicate for me. I suppose the answers could have >> been different, but I can't guess what mechanism actually leads to these >> results. Just idle curiosity on my

Re: Struggeling with collections

2016-03-07 Thread Jussi Piitulainen
Faling Dutchman writes: > I am just starting off in python, but have good knowledge of both Java > and C#. Now is the problem that I need to have multiple instances of ... > it prints: <__main__.Item object at 0x02EBF3B0> > > So that is not usefull to me. There can be an infinite amount of ...

Re: Pyhon 2.x or 3.x, which is faster?

2016-03-08 Thread Jussi Piitulainen
BartC writes: > On 08/03/2016 02:47, MRAB wrote: >> On 2016-03-08 01:33, BartC wrote: > >>> Compared with 2.7, 3.4 above is spending nearly an extra ten seconds >>> doing what? I can't understand why someone just wouldn't care. >>> >> Part of it will be that Python 2 has 2 integer types: 'int

Re: Tiny python code I dont understand

2016-03-08 Thread Jussi Piitulainen
ast writes: > Hello > lst = [(1,2,3), (4, 5,6)] sum(lst, ()) > (1, 2, 3, 4, 5, 6) > > Any explanations ? (() + (1,2,3)) + (4,5,6) -- https://mail.python.org/mailman/listinfo/python-list

Re: turtle ??

2016-03-09 Thread Jussi Piitulainen
Marko Rauhamaa writes: > Chris Angelico : > >> A Turkish keyboard should have dotless and dotted, uppercase and >> lowercase, all easily typed. > > BTW, typing any useful Unicode character is a major unsolved > problem. I have created this text file that contains a lot of unicode > characters with

Re: Read and count

2016-03-10 Thread Jussi Piitulainen
Val Krem writes: > Hi all, > > I am a new learner about python (moving from R to python) and trying > read and count the number of observation by year for each city. > > > The data set look like > city year x > > XC1 2001 10 > XC1 2001 20 > XC1 2002 20 > XC1 2002 10 > XC1 2002 10 >

Re: context managers inline?

2016-03-10 Thread Jussi Piitulainen
Chris Angelico writes: > On Fri, Mar 11, 2016 at 5:33 AM, Neal Becker wrote: >> Is there a way to ensure resource cleanup with a construct such as: >> >> x = load (open ('my file', 'rb)) >> >> Is there a way to ensure this file gets closed? > > Yep! > > def read_file(fn, *a, **kw): > with ope

Re: context managers inline?

2016-03-11 Thread Jussi Piitulainen
Paul Rubin writes: > Jussi Piitulainen writes: >> return ModeIO(f.read()) > > These suggestions involving f.read() assume the file contents are small > enough to reasonably slurp into memory. That's unlike the original > where "load" receives a stream

Re: Other difference with Perl: Python scripts in a pipe

2016-03-11 Thread Jussi Piitulainen
Alan Bawden writes: > Fillmore writes: > >> On 3/10/2016 7:08 PM, INADA Naoki wrote: > ... >> I don't like it. It makes Python not so good for command-line utilities >> > > You can easily restore the standard Unix command-line-friendly behavior > by doing: > > import signal > signal.signal(

Re: Simple exercise

2016-03-14 Thread Jussi Piitulainen
Steven D'Aprano writes: > Unfortunate or not, it seems to be quite common that "zip" > (convolution) discards items when sequences are of different lengths. Citation needed. Where is zip called convolution? Why should zip be called convolution? > See https://en.wikipedia.org/wiki/Convolution_%2

Re: Simple exercise

2016-03-15 Thread Jussi Piitulainen
Steven D'Aprano writes: > On Tuesday 15 March 2016 16:26, Jussi Piitulainen wrote: > >> Steven D'Aprano writes: >> >>> Unfortunate or not, it seems to be quite common that "zip" >>> (convolution) discards items when sequences are of differ

Re: How to waste computer memory?

2016-03-18 Thread Jussi Piitulainen
Ian Kelly writes: > On Thu, Mar 17, 2016 at 1:21 PM, Rick Johnson > wrote: >> In the event that i change my mind about Unicode, and/or for >> the sake of others, who may want to know, please provide a >> list of languages that *YOU* think handle Unicode better than >> Python, starting with the be

Re: DSLs in perl and python (Was sobering observation)

2016-03-19 Thread Jussi Piitulainen
Rustom Mody writes: > On Friday, March 18, 2016 at 4:17:06 AM UTC+5:30, MRAB wrote: >> Stick an "x" on the end of the regex: /something/x or s/old/new/x. > > Thanks! > > Is there somewhere a regexp 'introspection' API/capability available? > > ie if the re looks like > rexp = r""" > # DSL (instant

Re: How to waste computer memory?

2016-03-19 Thread Jussi Piitulainen
Steven D'Aprano writes: > And I don't understand this meme that indexing strings is not > important. Have people never (say) taken a slice of a string, or a > look-ahead, or something similar? > > i = mystring.find(":") > next_char = mystring[i+1] The point is that O(1) indexing and slicing *can

Re: Beginner Python Help

2016-03-19 Thread Jussi Piitulainen
Terry Reedy writes: > On 3/18/2016 3:04 AM, Alan Gabriel wrote: ... >> list1=(num.split()) > > list1 is a list of strings > >> maxim= (max(list1)) >> minim= (min(list1)) > > min and max compare the strings as strings, lexicographically > >> print(minim, maxim) ... > You failed to convert strin

Re: The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?)

2016-03-22 Thread Jussi Piitulainen
BartC writes: > Not everything fits into a for-loop you know! Why, take my own > readtoken() function: > > symbol = anything_other_than_skip_sym > > while symbol != skip_sym: > symbol = readnextsymbol() > > Of course, a repeat-until or repeat-while would suit this better (but > I don't kn

Re: The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?)

2016-03-22 Thread Jussi Piitulainen
Chris Angelico writes: > On Tue, Mar 22, 2016 at 11:52 PM, Jussi Piitulainen wrote: >> Now you can ask for the next item that satisfies a condition using a >> generator expression: >> >> next(symbol for symbol in stream if not symbol.isspace()) >> ---> '

Re: The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?)

2016-03-22 Thread Jussi Piitulainen
Chris Angelico writes: > On Wed, Mar 23, 2016 at 12:15 AM, Jussi Piitulainen wrote: >> Chris Angelico writes: >> >>> Or use filter(), which is sometimes clearer: >>> >>> # You probably want a more sophisticated function here >>> def nonspa

Re: The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?)

2016-03-22 Thread Jussi Piitulainen
Chris Angelico writes: > And yeah, the import is an option, but if I'm trying to explain stuff > to people, it's usually easier to grab a genexp (full flexibility, but > the complexity) than to play around with importing. When the function > you want exists and returns true for the things you want

Re: The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?)

2016-03-24 Thread Jussi Piitulainen
BartC writes: > On 24/03/2016 14:08, Jon Ribbens wrote: >> On 2016-03-24, BartC wrote: >>> I'd presumably have to do: >>> >>>for i in range(len(L)): >>> L[i]=0 >> >> That's kind've a weird thing to want to do; > > The thing I'm trying to demonstrate is changing an element of a list > that

Re: repeat items in a list

2016-03-27 Thread Jussi Piitulainen
Antonio Caminero Garcia writes: > On Saturday, March 26, 2016 at 11:12:58 PM UTC+1, beli...@aol.com wrote: >> I can create a list that has repeated elements of another list as >> follows: >> >> xx = ["a","b"] >> nrep = 3 >> print xx >> yy = [] >> for aa in xx: >> for i in range(nrep): >>

Re: Why lambda in loop requires default?

2016-03-27 Thread Jussi Piitulainen
gvim writes: > Given that Python, like Ruby, is an object-oriented language why > doesn't this: > > def m(): > a = [] > for i in range(3): a.append(lambda: i) > return a > > b = m() > for n in range(3): print(b[n]()) # => 2 2 2 I'm going to suggest two variations that may or may not wor

Re: Why lambda in loop requires default?

2016-03-27 Thread Jussi Piitulainen
gvim writes: > Given that Python, like Ruby, is an object-oriented language why > doesn't this: > > def m(): > a = [] > for i in range(3): a.append(lambda: i) > return a > > b = m() > for n in range(3): print(b[n]()) # => 2 2 2 > > ... work the same as this in Ruby: > > def m > a = []

Re: List of Functions

2016-03-28 Thread Jussi Piitulainen
Ben Bacarisse writes: > It's shame that anonymous functions (for that's what's being returned > here -- a function with no name) were born of a subject that used > arbitrary Greek letters for things. We seem stuck with the mysterious > but meaningless "lambda" for a very simple and useful idea.

Re: I need algorithm for my task

2014-11-06 Thread Jussi Piitulainen
Denis McMahon writes: > On Thu, 06 Nov 2014 15:14:05 +1100, Chris Angelico wrote: > > On Thu, Nov 6, 2014 at 3:00 PM, Denis McMahon wrote: > >> def baseword(s): > >> """find shortest sequence which repeats to generate s""" > >> return s[0:["".join([s[0:x]for k in range(int(len(s)/x)+1)])[0:

Re: SQLite3 in Python 2.7 Rejecting Foreign Key Insert

2014-11-23 Thread Jussi Piitulainen
Chris Angelico writes: > On Sun, Nov 23, 2014 at 7:21 PM, Frank Millman wrote: > > > To enable them, add the following - > > > > pragma foreign_keys = on; > > > > It works for me. > > Thanks, I went poking around briefly but didn't find that pragma. I didn't notice a pointer to the relevant docum

Re: Quotation Ugliness

2014-11-26 Thread Jussi Piitulainen
Tim Chase writes: > This doesn't jibe with the pairs of quotes you sent and your request > for nesting. In most popular shells, the majority of your "quote" > characters don't actually quote anything: > > bash$ echo // hello > hello Where did the // go? [...] > and has problems with things

Re: How is max supposed to work, especially key.

2014-12-04 Thread Jussi Piitulainen
Albert van der Horst writes: > Useful as that function [Python's max with a key] may be, it > shouldn't have been called max. The meaning of the key should be added to help(max), if it still isn't - "returns a maximal element or an element that maximizes the key". In some communities they call i

Re: How is max supposed to work, especially key.

2014-12-04 Thread Jussi Piitulainen
Albert van der Horst writes: > Chris Angelico wrote: > > If there's no clear maximum, it can't do any better than > > that. It's still returning something for which there is no > > greater. > > I agree that it is a useful function and that it is doing > the right thing. What is wrong is the name.

Re: How is max supposed to work, especially key.

2014-12-04 Thread Jussi Piitulainen
Steven D'Aprano writes: > Jussi Piitulainen wrote: > > > Would you also want sorted called something else when used with a > > key? Because it doesn't produce a sorted list of the keys either: > > > > >>> data = ("short", &quo

Re: Python re.search simple question

2014-12-07 Thread Jussi Piitulainen
Ganesh Pal writes: > why is re.search failing in the below case ?? Your pattern, '... level-based: [prev 0 , now 1]', matches a literal string '--- level-based: ' followed by 'p', 'r', 'e', 'v', ' ', '0', ..., or '1', none of which is the '[' found in your text at that position. Are you sure yo

Re: Python re.search simple question

2014-12-07 Thread Jussi Piitulainen
Jussi Piitulainen writes: > Ganesh Pal writes: > > > why is re.search failing in the below case ?? > > Your pattern, '... level-based: [prev 0 , now 1]', matches a literal > string '--- level-based: ' followed by 'p', 'r', 'e

Re: How to detect that a function argument is the default one

2014-12-10 Thread Jussi Piitulainen
Jean-Michel Pichavant writes: > If you like one-liners, > > def __init__(self, center=(0,0), radius=10, mass=None): > self.center = center > self.radius = radius > self.mass = (mass is None and radius**2) or mass That's not a one-liner. That's a one-liner: def __init__(self, center=

Re: list comprehension return a list and sum over in loop

2014-12-12 Thread Jussi Piitulainen
KK Sasa writes: > def p(x,t,point,z,obs): > d = x[0] > tau = [0]+[x[1:point]] > a = x[point:len(x)] > at = sum(i*j for i, j in zip(a, t)) > nu = [exp(z[k]*(at-d)-sum(tau[k])) for k in xrange(point)] > de = sum(nu, axis=0) > probability = [nu[k]/de for k in xrange(p

Re: Python console rejects an object reference, having made an object with that reference as its name in previous line

2014-12-14 Thread Jussi Piitulainen
Simon Evans writes: > I had another attempt at inputting the code perhaps with the right > indentation, I still get an error return, but not one that indicates > that the code has not been read, as you suggested. re:- > -- > > Py

Re: Hello World

2014-12-22 Thread Jussi Piitulainen
Steven D'Aprano writes: > Don't try this at home! > > # download_naked_pictures_of_jennifer_lawrence.py > import os > os.system("rm ――rf /") Not sure what that character is (those characters are) but it's not (they aren't) the hyphen that rm expects in its options, so: >>> os.system("rm ――rf

Re: CSV Error

2014-12-28 Thread Jussi Piitulainen
Skip Montanaro writes: > > ValueError: I/O operation on closed file > > > > Here is my code in a Python shell - > > > > >>> with open('x.csv','rb') as f: > > ... r = csv.DictReader(f,delimiter=",") > > >>> r.fieldnames > > The file is only open during the context of the with statement. > Inde

Re: Why For Loop Skips the Last element?

2015-01-01 Thread Jussi Piitulainen
Thuruv V writes: > Here's the list. . > > inlist = ["Fossil Women's Natalie Stainless Steel Watch Brown (JR1385)", > 'Balmer Swiss Made Veyron Mens Watch: Black Band/ Black Dial (62625241)', > 'Fortune NYC Ladies Quilted Dial Watch: Brown', > 'Jeanne Collection w/ Swarovski Elements Watch: Dark P

Re: Help with map python 2

2015-01-04 Thread Jussi Piitulainen
flebber writes: > In repsonse to this question: Write a program that prints the first > 100 members of the sequence 2, -3, 4, -5, 6, -7, 8. > > This is my solution it works but ugly. Seems respectable to me, except that you are taking fewer than 100 elements. But I'd prefer the expressions that

Re: where in Nan defined

2015-01-08 Thread Jussi Piitulainen
Marko Rauhamaa writes: > Ian Kelly: > > > To get nan as a literal just do: > > > > nan = float("nan") > > True, but that got me thinking: what standard Python math operation > evaluates to NaN? All manner of arithmetics gives overflow errors ("Numerical result out of range") but a literal wi

Re: where in Nan defined

2015-01-08 Thread Jussi Piitulainen
Chris Angelico writes: > On Fri, Jan 9, 2015 at 1:37 AM, Marko Rauhamaa wrote: > > > > True, but that got me thinking: what standard Python math > > operation evaluates to NaN? > > Subtracting infinity from infinity is one easy way. > > >>> 1e309 > inf > >>> 1e309-1e309 > nan I managed to get in

Re: Decimals and other numbers

2015-01-09 Thread Jussi Piitulainen
Devin Jeanpierre writes: [...] > domain of the natural numbers. Knuth says that thought of > combinatorially on the naturals, x**y counts the number of mappings > from a set of x values to a set of y values. It's the other way around, of course: from a set of y values to a set of x values. Whi

Re: Python 3 regex?

2015-01-13 Thread Jussi Piitulainen
alister writes: > On Tue, 13 Jan 2015 04:36:38 +, Steven D'Aprano wrote: > > > On Mon, 12 Jan 2015 19:48:18 +, Ian wrote: > > > >> My recommendation would be to write a recursive decent parser for > >> your files. > >> > >> That way will be easier to write, > > > > I know that writing

Re: lambdak: multi-line lambda implementation in native Python

2015-01-17 Thread Jussi Piitulainen
Steven D'Aprano writes: > Ah, wait, I forgot Ruby's brilliant "feature" that whitespace > *between* expressions is significant: > > [steve@ando ~]$ cat ~/coding/ruby/ws-example.rb > #!/usr/bin/ruby > > def a(x=4) > x+2 > end > > b = 1 > print "a + b => ", (a + b), "\n" > print "a+b => ",

Re: lambdak: multi-line lambda implementation in native Python

2015-01-17 Thread Jussi Piitulainen
Marko Rauhamaa writes: > Jussi Piitulainen: > > > a+ b => 7 # a() + b > > a +b => 3 # a(+b) => a(b) => a(1) = 1 + 2 > > > > I'm not quite fond of such surprise in programming language > > syntax. > > Yes, whoever came up with t

Re: lambdak: multi-line lambda implementation in native Python

2015-01-17 Thread Jussi Piitulainen
Marko Rauhamaa writes: > Seriously, though, I hate the optional semicolon rules of JavaScript > and Go. I dread the day when GvR gets it in his head to allow this > syntax in Python: > >average_drop_rate = cumulative_drop_count / >observation_period > > (although, it could be defined

Re: lambdak: multi-line lambda implementation in native Python

2015-01-17 Thread Jussi Piitulainen
Skip Montanaro writes: > On Sat, Jan 17, 2015 at 5:59 AM, Jussi Piitulainen wrote: > > How far do you want to go? Is "a b + c" the same as "a(b) + c" or > > the same as "a(b + c)"? > > I think there is only one practical interpretation, the o

Re: How to change the number into the same expression's string and vice versa?

2015-01-19 Thread Jussi Piitulainen
Peter Otten writes: > contro opinion wrote: > > Now how to change a1,a2,a3 into b1,b2,b3 and vice versa? > > a1=0xf4 > > a2=0o36 > > a3=011 > > > > b1='0xf4' > > b2='0o36' > > b3='011' > > Python 3.4.0 (default, Apr 11 2014, 13:05:11) > [GCC 4.8.2] on linux > Type "help", "copyright", "credits

Re: Idiomatic backtracking in Python

2015-01-25 Thread Jussi Piitulainen
Rustom Mody writes: > To add to Ian: > > The classic way of doing it in a functional framework is called: > "Replace failure by list of successes" > > https://rkrishnan.org/files/wadler-1985.pdf > > The things that have to go into it are > 1. Extensive use of list comprehensions > 2. Lazy lists

Re: Why does argparse return None instead of [] if an append action isn't used?

2015-01-26 Thread Jussi Piitulainen
Ian Kelly writes: > On Mon, Jan 26, 2015 at 8:50 AM, Adam Funk wrote: > > On 2015-01-26, Peter Otten wrote: > > > >> Adam Funk wrote: > >> > >>> On 2015-01-09, Ned Batchelder wrote: > for b in options.bar or (): > do_stuff(b) > >>> > >>> Do you mean "for b in options.bar or

Re: Is there a more elegant way to spell this?

2015-01-27 Thread Jussi Piitulainen
Neal Becker writes: > Is there a more elegant way to spell this? > > for x in [_ for _ in seq if some_predicate]: If you mean some_predicate(_), then possibly this. for x in filter(some_predicate, seq): handle(x) If you mean literally some_predicate, then perhaps this. if some_predicate:

Re: Is there a more elegant way to spell this?

2015-01-27 Thread Jussi Piitulainen
Neal Becker writes: > Jussi Piitulainen wrote: > > Neal Becker writes: > > > >> Is there a more elegant way to spell this? > >> > >> for x in [_ for _ in seq if some_predicate]: > > > > If you mean some_predicate(_), then possi

Re: Finding size of Variable

2014-02-12 Thread Jussi Piitulainen
Chris Angelico writes: > On Wed, Feb 12, 2014 at 6:49 PM, wrote: > > The day you find an operator working on the set of > > reals (R) and it is somehow "optimized" for N > > (the subset of natural numbers), let me know. ... > In Python, integers have arbitrary precision, but floats, Fractions,

Re: Working with the set of real numbers (was: Finding size of Variable)

2014-02-12 Thread Jussi Piitulainen
Chris Angelico writes: > On Wed, Feb 12, 2014 at 7:17 PM, Ben Finney wrote: > > What specific behaviour would, for you, qualify as “works with the > > set of real numbers in any way”? > > Being able to represent surds, pi, e, etc, for a start. It'd > theoretically be possible with an algebraic not

Re: Finding size of Variable

2014-02-12 Thread Jussi Piitulainen
Chris Angelico writes: > On Wed, Feb 12, 2014 at 7:57 PM, Jussi Piitulainen wrote: > >> In Python, integers have arbitrary precision, but floats, Fractions, > >> and Decimals, don't. Nearly any operation on arbitrarily large > >> numbers will be either more acc

Re: Recursive problem

2014-02-12 Thread Jussi Piitulainen
ahmed writes: > So we had to do a project for our python class and we came across a > recursive problem. The code we had to write was as follows: > > T(n) > if n == 1 > return 1 > else > for any number(k) between 1 and n - 1 > 2 * T(n-k) + 2^i - 1 > > from this we need to get the minimum number

Re: Explanation of list reference

2014-02-14 Thread Jussi Piitulainen
dave em writes: > He is asking a question I am having trouble answering which is how a > variable containing a value differs from a variable containing a > list or more specifically a list reference. My quite serious answer is: not at all. In particular, a list is a value. All those pointers to

Re: Explanation of list reference

2014-02-14 Thread Jussi Piitulainen
dave em writes: > On Friday, February 14, 2014 11:26:13 AM UTC-7, Jussi Piitulainen wrote: > > dave em writes: > > > > > He is asking a question I am having trouble answering which is > > > how a variable containing a value differs from a variable > > >

Re: Explanation of list reference

2014-02-16 Thread Jussi Piitulainen
Marko Rauhamaa writes: > Marko Rauhamaa : > > > Conceptually, the "everything is a reference" and the "small"/"big" > > distinction are equivalent (produce the same outcomes). The question > > is, which model is easier for a beginner to grasp. > > Case in point, if everything is a reference, ho

Re: Insert variable into text search string

2014-02-19 Thread Jussi Piitulainen
Kevin Glover writes: > These two lines are from a program that carries out a phrase search > of Wikipedia and returns the total number of times that the specific > phrase occurs. It is essential that the search contains an > apostrophe: > > results = w.search("\"of the cat's\"", type=ALL, start=1

Re: Can global variable be passed into Python function?

2014-02-21 Thread Jussi Piitulainen
dieter writes: > Sam writes: > > > I need to pass a global variable into a python function. > > Python does not really have the concept "variable". > > What appears to be a variable is in fact only the binding of an > object to a name. If you assign something to a variable, > all you do is bindi

Re: Remove comma from tuples in python.

2014-02-21 Thread Jussi Piitulainen
Gary Herron writes: > On 02/20/2014 10:49 PM, Jaydeep Patil wrote: > > I am getting below tuple from excel. > > How should i remove extra commas in each tuple to make it easy for > > operations. > > > > tuples is: > > seriesxlist1 = ((0.0), (0.01), (0.02), (0.03), (0.04), (0.05), (0.06), > > (0.0

Re: why i have the output of [None, None, None]

2014-04-10 Thread Jussi Piitulainen
length power writes: > >>> x=['','x1','x2','x3',' '] > >>> x > ['', 'x1', 'x2', 'x3', ' '] > >>> [print("ok") for it in x if it.strip() !=""] > ok > ok > ok > [None, None, None] > > i understand there are three 'ok' in the output,but why i have the > output of [None, None, None] It's a list

Re: Integer and float division [was Re: Why Python 3?]

2014-04-20 Thread Jussi Piitulainen
Steven D'Aprano writes: > It doesn't round, it truncates. > > [steve@ando ~]$ python2.7 -c "print round(799.0/100)" > 8.0 > [steve@ando ~]$ python2.7 -c "print 799/100" > 7 Seems it floors rather than truncates: $ python2.7 -c "from math import trunc;print trunc(799./-100)" -7 $ python2.7 -c "f

Re: how to split this kind of text into sections

2014-04-25 Thread Jussi Piitulainen
oyster writes: > I have a long text, which should be splitted into some sections, where > all sections have a pattern like following with different KEY. itertools.groupby, if you know how to extract a key from a given line. > And the /n/r can not be used to split Yet you seem to want to have ea

Re: Unicode 7

2014-05-02 Thread Jussi Piitulainen
Chris Angelico writes: > (common with dingbats fonts). With Unicode, the standard is to show > a little box *with the hex digits in it*. Granted, those boxes are a > LOT more readable for BMP characters than SMP (unless your text is > huge, six digits in the space of one character will make them p

Re: Values and objects

2014-05-10 Thread Jussi Piitulainen
Marko Rauhamaa writes: > To me, a variable is a variable is a variable. That works only in Python. Elsewhere, the sentence would be interpreted either as "a variable is True" or as "a variable is False" depending on whether a distinction without a difference is deemed helpful. -- https://mail.p

Re: Values and objects

2014-05-11 Thread Jussi Piitulainen
Marko Rauhamaa writes: > Rustom Mody: > > > On Saturday, May 10, 2014 2:39:31 PM UTC+5:30, Steven D'Aprano wrote: > >> > >> Personally, I don't imagine that there ever could be a language > >> where variables were first class values *exactly* the same as > >> ints, strings, floats etc. > > > > [.

Re: Values and objects

2014-05-11 Thread Jussi Piitulainen
Rustom Mody writes: > On Sunday, May 11, 2014 1:56:41 PM UTC+5:30, Jussi Piitulainen wrote: > > Marko Rauhamaa writes: > > > Rustom Mody: > > > > > > > On Saturday, May 10, 2014 2:39:31 PM UTC+5:30, Steven D'Aprano wrote: > > > >> >

Re: Is there a function that applies list of functions to a value?

2013-08-28 Thread Jussi Piitulainen
AdamKal writes: > Hi, > > From time to time I have to apply a series of functions to a value > in such a way: > > func4(func3(func2(func1(myval > > I was wondering if there is a function in standard library that > would take a list of functions and a initial value and do the above > like t

Re: Is there a function that applies list of functions to a value?

2013-08-28 Thread Jussi Piitulainen
Tim Chase writes: > On 2013-08-28 05:52, AdamKal wrote: > > From time to time I have to apply a series of functions to a value > > in such a way: > > > > func4(func3(func2(func1(myval > > > > I was wondering if there is a function in standard library that > > would take a list of functions a

Re: semicolon at end of python's statements

2013-08-31 Thread Jussi Piitulainen
Steven D'Aprano writes: > We really are spoiled for choice here. We can write any of these: > > # Option 1 > for spam in sequence: > if predicate(spam): > process(spam) # Option 1.5 for spam in sequence: if not predicate(spam): continue process(spam) This saves an indent lev

Re: semicolon at end of python's statements

2013-08-31 Thread Jussi Piitulainen
Paul Rudin writes: > Jussi Piitulainen writes: > > > # Option 1.5 > > for spam in sequence: > > if not predicate(spam): continue > > process(spam) > > > > This saves an indent level. > > Just out of interest: is saving an indent level a

Re: lambda - strange behavior

2013-09-20 Thread Jussi Piitulainen
Kasper Guldmann writes: > I was playing around with lambda functions, but I cannot seem to > fully grasp them. I was running the script below in Python 2.7.5, > and it doesn't do what I want it to. Are lambda functions really > supposed to work that way. How do I make it work as I intend? > > f =

Re: Antispam measures circumventing

2013-09-20 Thread Jussi Piitulainen
Jugurtha Hadjar writes: > Supposing my name is John Doe and the e-mail is john@hotmail.com, > my e-mail was written like this: > > removemejohn.dospames...@removemehotmail.com' > > With a note saying to remove the capital letters. > > Now, I wrote this : > > for character in my_string: > .

Re: Functional Programming and python

2013-09-24 Thread Jussi Piitulainen
Vito De Tullio writes: > rusi wrote: > > > [Not everything said there is correct; eg python supports currying > > better [than haskell which is surprising considering that > > Haskell's surname is [Curry!] > > AFAIK python does not support currying at all (if not via some > decorators or somethi

Re: Functional Programming and python

2013-09-24 Thread Jussi Piitulainen
rusi writes: > Without resorting to lambdas/new-functions: > With functools.partial one can freeze any subset of a > function(callable's) parameters. > > In Haskell one can only freeze the first parameter or at most with > a right section the second You have an f of type A -> B -> C -> D -> E

Re: Functional Programming and python

2013-09-24 Thread Jussi Piitulainen
rusi writes: > On Tuesday, September 24, 2013 1:12:51 PM UTC+5:30, Jussi Piitulainen wrote: > > rusi writes: > > > > > Without resorting to lambdas/new-functions: > > > With functools.partial one can freeze any subset of a > > > function(callable

Re: Handling 3 operands in an expression without raising an exception

2013-09-26 Thread Jussi Piitulainen
Νίκος writes: > How can i wrote the two following lines so for NOT to throw out > KeyErrors when a key is missing? > > city = gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] ) or ... > I was under the impression that the 'or' operator was handling this > in case one operand was failing

Re: Handling 3 operands in an expression without raising an exception

2013-09-26 Thread Jussi Piitulainen
Νίκος writes: > Σ�ις 26/9/2013 10:48 πμ, ο/η Jussi Piitulainen > έγ�α�ε: > ί�ος writes: > > > >> How can i wrote the two following lines so for NOT to throw out > >> KeyErrors when a key is missing? > >> > >> city = gi.time_zone_by_addr( os.envir

<    1   2   3   4   5   6   7   >