Re: Append to python List

2013-05-09 Thread Jussi Piitulainen
RAHUL RAJ writes: > Checkout the following code: > > sample2 = [x+y for x in range(1,10) for y in range(1,10) if x!=y] > output=[] > output=[x for x in sample2 if x not in output] > > the output I get is > 3 4 5 6 7 8 9 10 3 5 6 7 8 9 10 11 4 5 7 8 9 10 11 12 5 6 7 9 10 11 > 12 13 6 7 8 9 11

Re: Append to python List

2013-05-09 Thread Jussi Piitulainen
8 Dihedral writes: > This is just the handy style for a non-critical loop. > In a critical loop, the number of the total operation counts > does matter in the execution speed. Do you use speed often? -- http://mail.python.org/mailman/listinfo/python-list

Re: Style question -- plural of class name?

2013-05-09 Thread Jussi Piitulainen
Neil Cerutti writes: > If there's no chance for confusion between a class named FooEntry > and another named FooEntries, then the first attempt seems best. > Pluralize a class name by following the usual rules, e.g., > "strings" and "ints". Like "strings" would be "foo entries". Which might work

Re: Append to python List

2013-05-11 Thread Jussi Piitulainen
Chris Angelico writes: > On Thu, May 9, 2013 at 9:30 PM, Jussi Piitulainen wrote: > > 8 Dihedral writes: > > > >> This is just the handy style for a non-critical loop. > >> In a critical loop, the number of the total operation counts > >> does matter

Re: Determine actually given command line arguments

2013-05-15 Thread Jussi Piitulainen
Colin J. Williams writes: > On 15/05/2013 2:34 AM, Henry Leyh wrote: > > Hello, > > I am writing a program that gets its parameters from a combination > > of config file (using configparser) and command line arguments > > (using argparse). Now I would also like the program to be able to > > _wri

Re: Determine actually given command line arguments

2013-05-15 Thread Jussi Piitulainen
Henry Leyh writes: > But now I would also like to be able to _write_ such a config file > FILE that can be read in a later run. And FILE should contain only > those arguments that were given on the command line. > > Say, I tell argparse to look for arguments -s|--sopt STRING, > -i|--iopt INT, -b

Re: How to run a python script twice randomly in a day?

2013-05-21 Thread Jussi Piitulainen
Chris Angelico writes: > > On 20May2013 15:05, Avnesh Shakya wrote: > > So your call picks a number from 0..58, not 0..59. > > Say randrange(0,60). Think "start, length". > > Nitpick: It's not start, length; it's start, stop-before. If the > start is 10 and the second argument is 20, you'll g

Re: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-25 Thread Jussi Piitulainen
Roy Smith writes: > In article <78192328-b31b-49d9-9cd6-ec742c092...@googlegroups.com>, > lokeshkopp...@gmail.com wrote: > > > On Friday, May 24, 2013 1:34:51 PM UTC+5:30, lokesh...@gmail.com wrote: > > > i need to write a code which can sort the list in order of 'n' > > > without use builtin fu

Re: Solving the problem of mutual recursion

2013-05-26 Thread Jussi Piitulainen
Peter Brooks writes: > I'm not sure if this'll interest anybody, but I expect that I'm > going to get some mutual recursion in my simulation, so I needed to ... > returned, then this solution won't help you. Often, though, you're > not interested in what's returned and would just like the routine

Re: Short-circuit Logic

2013-05-30 Thread Jussi Piitulainen
Steven D'Aprano writes: > On Thu, 30 May 2013 13:45:13 +1000, Chris Angelico wrote: > > > Let's suppose someone is told to compare floating point numbers by > > seeing if the absolute value of the difference is less than some > > epsilon. > > Which is usually the wrong way to do it! Normally one

Re: Short-circuit Logic

2013-05-30 Thread Jussi Piitulainen
Steven D'Aprano writes: > On Thu, 30 May 2013 10:22:02 +0300, Jussi Piitulainen wrote: > > > I wonder why floating-point errors are not routinely discussed in > > terms of ulps (units in last position). There is a recipe for > > calculating the difference of two f

Re: How to store a variable when a script is executing for next time execution?

2013-06-06 Thread Jussi Piitulainen
Avnesh Shakya writes: > I am running a python script and it will create a file name like > filename0.0.0 and If I run it again then new file will create one > more like filename0.0.1.. my code is- > > i = 0 > for i in range(1000): > try: > with open('filename%d.%d.%d.json'%(0,0,i,

Re: Split a list into two parts based on a filter?

2013-06-12 Thread Jussi Piitulainen
Roy Smith writes: > We've been in the twilight zone for a while. That's when the fun > starts. But, somewhat more seriously, I wonder what, exactly, it is > that freaks people out about: > > [(new_songs if s.is_new() else old_songs).append(s) for s in songs] > > Clearly, it's not the fact

Re: A certainl part of an if() structure never gets executed.

2013-06-14 Thread Jussi Piitulainen
Nick the Gr33k writes: > >>> name="abcd" > >>> month="efgh" > >>> year="ijkl" > > >>> print(name or month or year) > abcd > > Can understand that, it takes the first string out of the 3 strings > that has a truthy value. > > >>> print("k" in (name and month and year)) > True > > No clue.

Re: A certainl part of an if() structure never gets executed.

2013-06-14 Thread Jussi Piitulainen
Nick the Gr33k writes: > On 14/6/2013 11:28 πμ, Jussi Piitulainen wrote: > > >>>> 'Parker' and 'May' and '2001' > > '2001' > > But why? > > that expression should return True since all stings are not empty.

Re: A certainl part of an if() structure never gets executed.

2013-06-14 Thread Jussi Piitulainen
Nick the Gr33k writes: > On 14/6/2013 12:21 μμ, Jussi Piitulainen wrote: > > Nick the Gr33k writes: > >> On 14/6/2013 11:28 πμ, Jussi Piitulainen wrote: > >> > >>>>>> 'Parker' and 'May' and '2001' > >>> '

Re: A certainl part of an if() structure never gets executed.

2013-06-14 Thread Jussi Piitulainen
Nick the Gr33k writes: > >>> (a or b or c) > 'abcd' > > This for me, should evaluate to True but instead it has been > evaluated to the first variable's value, which is a truthy value of > course since its not an empty string, but shouldn't it return True > instead? In your own programs, write

Re: Eval of expr with 'or' and 'and' within

2013-06-14 Thread Jussi Piitulainen
Nick the Gr33k writes: > Why return first or last value? > > because that will evaluate to the correct Boolean value That value will either behave exactly the same as the Boolean value you call correct, or else it will be more useful. That is, most of the time it doesn't matter, and when it

Re: A certainl part of an if() structure never gets executed.

2013-06-16 Thread Jussi Piitulainen
Nick the Gr33k writes: > On 16/6/2013 12:22 μμ, Denis McMahon wrote: > > For example, in Python > > > > a = 6 > > b = a > > c = 6 > > > > a and b point to one memory location that contains the value 6 > > c points to a different memory location that contains the value 6 > > I believe you are mista

Re: Default Value

2013-06-19 Thread Jussi Piitulainen
Ahmed Abdulshafy writes: > I'm reading the Python.org tutorial right now, and I found this part > rather strange and incomprehensible to me > > Important warning: The default value is evaluated only once. This > makes a difference when the default is a mutable object such as a > list, dictionary

Re: A few questiosn about encoding

2013-06-20 Thread Jussi Piitulainen
Rick Johnson writes: > On Thursday, June 20, 2013 9:04:50 AM UTC-5, Andrew Berg wrote: > > On 2013.06.20 08:40, Rick Johnson wrote: > > > > then what is the purpose of a Unicode Braille character set? > > Two dimensional characters can be made into 3 dimensional shapes. > > Yes in the real worl

Re: Simple I/O problem can't get solved

2013-06-21 Thread Jussi Piitulainen
nickgan@windowslive.com writes: > I think I coded it correctly but still I get no output. I do not > have any errors I just do not get any output. > > This is the code: > > *** > import is_palindrome > > filename = raw_input('Enter a file: ') # A text file > f = open(filename) > while True:

Re: How is this evaluated

2013-07-04 Thread Jussi Piitulainen
Arturo B writes: > I'm making this exercise: (Python 3.3) > > Write a function translate() that will translate a text into > "rövarspråket" (Swedish for "robber's language"). That is, double > every consonant and place an occurrence of "o" in between. For > example, translate("this is fun") shoul

Re: [newbie] problem with data (different behaviour between batch and interactive use)

2012-06-27 Thread Jussi Piitulainen
Jean Dupont writes: > If I start python interactively I can separate the fields as > follows: > >measurement=+3.874693E01,+9.999889E03,+9.91E+37,+1.876[...] > >print measurement[0] > 0.3874693 [...] > The script does this: > measurement=serkeith.readline().replace('\x11','').replace([...] > pr

Re: Regex Question

2012-08-18 Thread Jussi Piitulainen
Frank Koshti writes: > not always placed in HTML, and even in HTML, they may appear in > strange places, such as Hello. My specific issue > is I need to match, process and replace $foo(x=3), knowing that > (x=3) is optional, and the token might appear simply as $foo. > > To do this, I decided to

Re: Objects in Python

2012-08-22 Thread Jussi Piitulainen
shaun writes: > I'm having an issue its my first time using python and i set up a > class one of the methods is supposed to return a string but instead > returns: > > 389E0>> > > Im very new to python and the object orientated feature doesnt seem > to be as well put together as Java. Can anyone

Re: Objects in Python

2012-08-23 Thread Jussi Piitulainen
Steven D'Aprano writes: > On Wed, 22 Aug 2012 23:49:17 -0500, Evan Driscoll wrote: > > > On 8/22/2012 18:58, Ben Finney wrote: > >> You haven't discovered anything about types; what you have > >> discovered is that Python name bindings are not variables. > >> > >> In fact, Python doesn't have var

Re: Boolean function on variable-length lists

2012-09-12 Thread Jussi Piitulainen
Libra writes: > Hello, > > I need to implement a function that returns 1 only if all the values > in a list satisfy given constraints (at least one constraint for > each element in the list), and zero otherwise. > > For example, I may have a list L = [1, 2, 3, 4] and the following > constraints:

Re: Boolean function on variable-length lists

2012-09-12 Thread Jussi Piitulainen
Libra writes: > On Wednesday, September 12, 2012 3:02:44 PM UTC+2, Jussi Piitulainen wrote: > > > So you would associate each constraint with an index. You could > > maintain a list of constraints and apply it to the values as > > follows: > > Yes, even though t

Re: A little morning puzzle

2012-09-19 Thread Jussi Piitulainen
Neal Becker writes: > I have a list of dictionaries. They all have the same keys. I want > to find the set of keys where all the dictionaries have the same > values. Suggestions? Literally-ish: { key for key, val in ds[0].items() if all(val == d[key] for d in ds) } -- http://mail.python.org/m

Re: Exact integer-valued floats

2012-09-21 Thread Jussi Piitulainen
Steven D'Aprano writes: > Python floats can represent exact integer values (e.g. 42.0), but above a > certain value (see below), not all integers can be represented. For > example: > > py> 1e16 == 1e16 + 1 # no such float as 10001.0 > True > py> 1e16 + 3 == 1e16 + 4 # or 1

Re: regular expression : the dollar sign ($) work with re.match() or re.search()

2012-09-26 Thread Jussi Piitulainen
iMath writes: > I only know the dollar sign ($) will match a pattern from the end of > a string, but which method does it work with, re.match() or > re.search() It works with both. With re.match, the pattern has to match at the start of the string _and_ the $ has to match the end of the string (o

Re: regular expression : the dollar sign ($) work with re.match() or re.search()

2012-09-26 Thread Jussi Piitulainen
Alister writes: > On Wed, 26 Sep 2012 10:48:00 +0300, Jussi Piitulainen wrote: > > > iMath writes: > > > >> I only know the dollar sign ($) will match a pattern from the end > >> of a string, but which method does it work with, re.match() or > >>

Re: "#!/usr/bin/env python" vs. "#!/usr/bin/python"?

2012-09-28 Thread Jussi Piitulainen
Gilles writes: > #!/usr/bin/env python > #!/usr/bin/python > > What's the difference? Not much if your python is /usr/bin/python: env looks for python and finds the same executable. When python is not /usr/bin/python but something else that is still found by your system, /usr/bin/env still find

Re: Unpaking Tuple

2012-10-09 Thread Jussi Piitulainen
Dave Angel writes: > On 10/09/2012 02:07 AM, Bob Martin wrote: > > in 682592 20121008 232126 "Prasad, Ramit" wrote: [snip mess] > > How does one unpack this post? ;-) > > Since that's not the way it arrived here, i have to ask, how do you > get these posts? Are you subscribed to individual mess

Re: mangled messages (was: Unpaking Tuple)

2012-10-09 Thread Jussi Piitulainen
Tim Chase writes: > On 10/09/12 02:22, Jussi Piitulainen wrote: > >>> in 682592 20121008 232126 "Prasad, Ramit" wrote: > > [snip mess] > >>> How does one unpack this post? ;-) > >> > >> Since that's not the way it arrived here

Re: How to use "while" within the command in -c option of python?

2012-10-13 Thread Jussi Piitulainen
Chris Angelico writes: > Here's a side challenge. In any shell you like, start with this > failing statement, and then fix it without retyping anything: > > sikorsky@sikorsky:~$ python -c "a=1; if a: print(a)" > File "", line 1 > a=1; if a: print(a) > ^ > SyntaxError: invalid synt

Re: a prob.. error in prog ..dont knw how to correct

2012-10-21 Thread Jussi Piitulainen
inshu chauhan writes: > I am new to python and have a little problem to solve .. i have an > array with x, y, z co-ordinates in it as a tuple. I am trying to find > the distance between each point and sorting the points according to > the min distance.. i have tried a prog but m stuck bcoz of this

Re: Multi-dimensional list initialization

2012-11-07 Thread Jussi Piitulainen
Steven D'Aprano writes: > On Wed, 07 Nov 2012 00:23:44 +, MRAB wrote: > > I prefer the term "reference semantics". > > Oh good, because what the world needs is yet another name for the > same behaviour. > > - call by sharing > - call by object sharing > - call by object reference > - call by

Re: Understanding '?' in regular expressions

2012-11-16 Thread Jussi Piitulainen
krishna.k.kish...@gmail.com writes: > Can someone explain the below behavior please? > > >>> re1 = re.compile(r'(?:((?:1000|1010|1020))[ ]*?[\,]?[ ]*?){1,3}') > >>> re.findall(re_obj,'1000,1020,1000') > ['1000'] > >>> re.findall(re_obj,'1000,1020, 1000') > ['1020', '1000'] > > However when I use

Re: scope, function, mutable

2012-12-04 Thread Jussi Piitulainen
gusa...@gmail.com writes: > What is the appropriate definition for the following behavior in > Python 2.7 (see code below). > > Both functions have assignment in it (like "x = ") so I assume, that > x is a local variable in both functions. It's a local variable in both functions because it's a fo

Re: Running a python script under Linux

2012-12-13 Thread Jussi Piitulainen
Steven D'Aprano writes: > I have a Centos system which uses Python 2.4 as the system Python, so I > set an alias for my personal use: > > [steve@ando ~]$ which python > alias python='python2.7' > /usr/local/bin/python2.7 > > > When I call "python some_script.py" from the command line,

Re: counting how often the same word appears in a txt file...But my code only prints the last line entry in the txt file

2012-12-19 Thread Jussi Piitulainen
dgcosgr...@gmail.com writes: > Hi Iam just starting out with python...My code below changes the txt > file into a list and add them to an empty dictionary and print how > often the word occurs, but it only seems to recognise and print the > last entry of the txt file. Any help would be great. > >

Re: how to detect the encoding used for a specific text data ?

2012-12-20 Thread Jussi Piitulainen
iMath writes: > how to detect the encoding used for a specific text data ? The practical thing to do is to try an encoding and see whether you find the expected frequent letters of the relevant languages in the decoded text, or the most frequent words. This is likely to help you decide between s

Re: how to detect the encoding used for a specific text data ?

2012-12-20 Thread Jussi Piitulainen
iMath writes: > which package to use ? Read the text in as a "bytes object" (bytes), then it has a .decode method that you can experiment with. Strings (str) are Unicode and have an .encode method. These methods allow you to specify a desired encoding and and what to do when there are errors. he

Re: Finding the name of a function while defining it

2012-12-29 Thread Jussi Piitulainen
Abhas Bhattacharya writes: [...] > If i call one() and two() respectively, i would like to see "one" > and "two". I dont have much knowledge of lambda functions, neither > am i going to use them, so that's something I cant answer. It's not about lambda. The following does not contain lambda. Wha

Re: reduce expression to test sublist

2013-01-05 Thread Jussi Piitulainen
Asim writes: > Hi All > > The following reduce expression checks if every element of list lst1 > is present in list lst2. It works as expected for integer lists but > for lists of strings, it always returns False. > >reduce( lambda x,y: (x in lst2) and (y in lst2), lst1) Possibly this:

Re: functon invoke or not

2013-01-09 Thread Jussi Piitulainen
skyworld writes: > Hi, > > I see someone's code as this: > > class ABC: > def __init__(self, env): > ... > self.jmpTable['batchQ']['submit_job'] = self.lsf_submit > ... > def lsf_submit(self, cmd,env): > . > > what confused me is why

Re: please i need explanation

2013-01-11 Thread Jussi Piitulainen
kwakukwat...@gmail.com writes: > 11.01.2013 17:35, kwakukwat...@gmail.com wrote: > > def factorial(n): > > if n<2: > > return 1 > > f = 1 > > while n>= 2: > > f *= n > > f -= 1 > > return f > > please it works.but don’t get why the return 1 and th

Re: Else statement executing when it shouldnt

2013-01-23 Thread Jussi Piitulainen
Thomas Boell writes: > Using a keyword that has a well-understood meaning in just about > every other programming language on the planet *and even in > English*, redefining it to mean something completely different, and > then making the syntax look like the original, well-understood > meaning --

Re: Postpone evaluation of argument

2012-02-11 Thread Jussi Piitulainen
Righard van Roy writes: > Hello, > > I want to add an item to a list, except if the evaluation of that item > results in an exception. > I could do that like this: > > def r(x): > if x > 3: > raise(ValueError) > > try: > list.append(r(1)) > except: > pass > try: > list.a

Re: Python math is off by .000000000000045

2012-02-22 Thread Jussi Piitulainen
Alec Taylor writes: > Simple mathematical problem, + and - only: > > >>> 1800.00-1041.00-555.74+530.74-794.95 > -60.9500045 > > That's wrong. Not by much. I'm not an expert, but my guess is that the exact value is not representable in binary floating point, which most programming langua

Re: Documentation, assignment in expression.

2012-03-26 Thread Jussi Piitulainen
Kiuhnm writes: > On 3/26/2012 10:52, Devin Jeanpierre wrote: > > On Sun, Mar 25, 2012 at 11:16 AM, Kiuhnm > > wrote: > >> On 3/25/2012 15:48, Tim Chase wrote: > >>> > >>> The old curmudgeon in me likes the Pascal method of using "=" for > >>> equality-testing, and ":=" for assignment which feels

Re: "convert" string to bytes without changing data (encoding)

2012-03-28 Thread Jussi Piitulainen
Peter Daum writes: > ... I was under the illusion, that python (like e.g. perl) stored > strings internally in utf-8. In this case the "conversion" would simple > mean to re-label the data. Unfortunately, as I meanwhile found out, this > is not the case (nor the "apple encoding" ;-), so it would i

Re: string interpolation for python

2012-04-02 Thread Jussi Piitulainen
Yingjie Lan writes: > Clearly dynamic strings are much more powerful, > allowing arbitrary expressions inside. It is also > more terse and readable, since we need no dictionary. ... > On the implementation, I would suppose new  > syntax is needed (though very small). I don't think you need any ne

Re: Regular expressions, help?

2012-04-18 Thread Jussi Piitulainen
Sania writes: > So I am trying to get the number of casualties in a text. After 'death > toll' in the text the number I need is presented as you can see from > the variable called text. Here is my code > I'm pretty sure my regex is correct, I think it's the group part > that's the problem. > I am

Re: Regular expressions, help?

2012-04-19 Thread Jussi Piitulainen
Sania writes: > On Apr 19, 2:48 am, Jussi Piitulainen > wrote: > > Sania writes: > > > So I am trying to get the number of casualties in a text. After 'death > > > toll' in the text the number I need is presented as you can see from > > > th

Re: can I overload operators like "=>", "->" or something like that?

2012-04-20 Thread Jussi Piitulainen
Kiuhnm writes: > On 4/20/2012 17:50, Nobody wrote: > > On Thu, 19 Apr 2012 12:28:50 -0700, dmitrey wrote: > > > >> can I somehow overload operators like "=>", "->" or something > >> like that? (I'm searching for appropriate overload for logical > >> implication "if a then b") > > > > You cannot cr

Re: finding a regular expression in a file

2012-04-24 Thread Jussi Piitulainen
"S.B" writes: > Hello friends. > > Newb question here. > I'm trying to find an efficient way to "grep" a file with python. > The problem is that all the solutions I find on the web read a line > at a time from the file with a "for line in" loop and check each > line for the RE instead of sweeping

Re: Trouble splitting strings with consecutive delimiters

2012-04-30 Thread Jussi Piitulainen
deuteros writes: > I'm using regular expressions to split a string using multiple > delimiters. But if two or more of my delimiters occur next to each > other in the string, it puts an empty string in the resulting > list. For example: > > re.split(':|;|px', "width:150px;height:50px;float:

Re: numpy (matrix solver) - python vs. matlab

2012-05-01 Thread Jussi Piitulainen
"someone" writes: > except it would be nice to learn some things for future use (for > instance understanding SVD more - perhaps someone geometrically can > explain SVD, that'll be really nice, I hope)... The Wikipedia article looks promising to me:

Re: Dynamic comparison operators

2012-05-24 Thread Jussi Piitulainen
Alain Ketterlin writes: > mlangenho...@gmail.com writes: > > > I would like to pass something like this into a function > > test(val1,val2,'>=') > > > > and it should come back with True or False. > > def test(x,y,c): > return c(x,y) > > Call with: test(v1,v2, lambda x,y:x<=y ). A bit noisy

Re: Passing ints to a function

2012-06-09 Thread Jussi Piitulainen
stayvoid writes: > > You want to unpack the list: > > > > function(*a)  # like function(a[0], a[1], a[2], ...) > > Awesome! I forgot about this. Here's something you could have thought of for yourself even when you didn't remember that Python does have special built-in support for applying a fun

Re: Py3.3 unicode literal and input()

2012-06-18 Thread Jussi Piitulainen
jmfauth writes: > Thinks are very clear to me. I wrote enough interactive > interpreters with all available toolkits for Windows >>> r = input() u'a Traceback (most recent call last): File "", line 1, in SyntaxError: u'a Er, no, not really :-) -- http://mail.python.org/mailman/listinfo/pytho

Re: Py3.3 unicode literal and input()

2012-06-18 Thread Jussi Piitulainen
Andrew Berg writes: > On 6/18/2012 11:32 AM, Jussi Piitulainen wrote: > > jmfauth writes: > > > >> Thinks are very clear to me. I wrote enough interactive > >> interpreters with all available toolkits for Windows > > > >>>> r = input() >

Re: Something is rotten in Denmark...

2011-06-02 Thread Jussi Piitulainen
Alain Ketterlin writes: > Steven D'Aprano writes: > > I agree it's not intuitive. But where does it say that programming > > language semantics must always be intuitive? > > Nowhere. But going against generally accepted semantics should at > least be clearly indicated. Lambda is one of the oldest

Re: Something is rotten in Denmark...

2011-06-02 Thread Jussi Piitulainen
rusi writes: > So I tried: > Recast the comprehension as a map > Rewrite the map into a fmap (functionalmap) to create new bindings > > def fmap(f,lst): > if not lst: return [] > return [f(lst[0])] + fmap(f, lst[1:]) > > Still the same effects. > > Obviously I am changing it at the wron

Re: Something is rotten in Denmark...

2011-06-03 Thread Jussi Piitulainen
Alain Ketterlin writes: > Gregory Ewing writes: > > > Alain Ketterlin wrote: > >> But going against generally accepted semantics should at least be > >> clearly indicated. Lambda is one of the oldest computing > >> abstraction, and they are at the core of any functional > >> programming language.

Re: Something is rotten in Denmark...

2011-06-05 Thread Jussi Piitulainen
rusi writes: > On Jun 3, 11:17 am, Jussi Piitulainen wrote: > > rusi writes: > > > So I tried: > > > Recast the comprehension as a map > > > Rewrite the map into a fmap (functionalmap) to create new bindings > > > > > def fmap(f,lst): > &

Re: Something is rotten in Denmark...

2011-06-05 Thread Jussi Piitulainen
rusi writes: > On Jun 5, 5:03 pm, Jussi Piitulainen wrote: > > rusi writes: > > > On Jun 3, 11:17 am, Jussi Piitulainen wrote: > > > > rusi writes: > > > > > So I tried: > > > > > Recast the comprehension as a map > > > &

Re: os.path.walk() to get full path of all files

2011-03-17 Thread Jussi Piitulainen
Laurent Claessens writes: > > file_list = [] > > for root, _, filenames in os.walk(root_path): > > for filename in filenames: > > file_list.append(os.path.join(root, filename)) > > What does the notation "_" stands for ? Is it a sort of /dev/null ? >>> x, _, y = 1, "hukairs",

Re: Feature suggestion -- return if true

2011-04-18 Thread Jussi Piitulainen
Gregory Ewing writes: > Chris Angelico wrote: > > > Question: How many factorial functions are implemented because a > > program needs to know what n! is, and how many are implemented to > > demonstrate recursion (or to demonstrate the difference between > > iteration and recursion)? :) (I can't

Re: checking if a list is empty

2011-05-08 Thread Jussi Piitulainen
Steven D'Aprano writes: > Lisp uses the empty list and the special atom NIL as false values, > any other s-expression is true. Scheme is different: it defines a > special false atom, and empty lists are considered true. In Ruby, I'll inject a pedantic note: there is only one false value in both L

Re: Faster Recursive Fibonacci Numbers

2011-05-17 Thread Jussi Piitulainen
geremy condra writes: > or O(1): > > φ = (1 + sqrt(5)) / 2 > def fib(n): > numerator = (φ**n) - (1 - φ)**n > denominator = sqrt(5) > return round(numerator/denominator) > > Testing indicates that it's faster somewhere around 7 or so. And increasingly inaccurate from 71 on. -- http:

Re: Python 3.2 bug? Reading the last line of a file

2011-05-25 Thread Jussi Piitulainen
tkp...@hotmail.com writes: > Looking through the docs did not clarify my understanding of the > issue. Why can I not split on '\t' when reading in binary mode? You can split on b'\t' to get a list of byteses, which you can then decode if you want them as strings. You can decode the bytes to get

Re: scope of function parameters

2011-05-30 Thread Jussi Piitulainen
Laurent Claessens writes: > Le 30/05/2011 11:02, Terry Reedy a écrit : > > On 5/30/2011 3:38 AM, Laurent wrote: > > > >> Cool. I was thinking that "5" was the name, but > >> >>> 5.__add__(6) > >> File "", line 1 > >> 5.__add__(6) > > > > > > Try 5 .__add__(6) > > What is the rationale behind

Re: Something is rotten in Denmark...

2011-05-31 Thread Jussi Piitulainen
harrismh777 writes: > >>> fs=[] > >>> fs = [(lambda n: i + n) for i in range(10)] > >>> [fs[i](1) for i in range(10)] > [10, 10, 10, 10, 10, 10, 10, 10, 10, 10] <=== not good > > ( that was a big surprise! . . . ) > ( let's try it another way . . . ) The ten functions share the

Re: Something is rotten in Denmark...

2011-05-31 Thread Jussi Piitulainen
Thomas Rachel writes: > Am 31.05.2011 12:08 schrieb Jussi Piitulainen: > > > The same sharing-an-i thing happens here: > > > >>>> fs = [] > >>>> for i in range(4): > > ...fs.append(lambda n : i + n) > > ... > >>>

Re: Comparison operators in Python

2011-06-01 Thread Jussi Piitulainen
Anirudh Sivaraman writes: > I am a relative new comer to Python. I see that typing is strongly > enforced in the sense you can't concatenate or add a string and an > integer. However comparison between a string and an integer seems to > be permitted. Is there any rationale behind this ? In Python

Re: Asynchronous programming

2016-08-11 Thread Jussi Piitulainen
Michael Selik writes: > On Thu, Aug 11, 2016 at 11:46 AM Michael Selik > wrote: > >> On Thu, Aug 11, 2016 at 11:01 AM Steven D'Aprano < >> steve+pyt...@pearwood.info> wrote: >> >>> That ... looks wrong. You're taking something which looks like a procedure >>> in the first case (trn.execute), so

Re: Finding the first index in a list greater than a particular value

2016-08-14 Thread Jussi Piitulainen
Atri Mahapatra writes: > I have a list of dictionaries which look like this: > [{'Width': 100, 'Length': 20.0, 'Object': 'Object1'}, {'Width': 12.0, > 'Length': 40.0, 'Object': 'Object2'}.. so on till 10] > > I would like to find the first index in the list of dictionaries whose > length is

Re: I am new to python. I have a few questions coming from an armature!

2016-08-16 Thread Jussi Piitulainen
Lawrence D’Oliveiro writes: > On Tuesday, August 16, 2016 at 6:26:01 PM UTC+12, Paul Rudin wrote: >> sohcahtoa82 writes: >>> squared_plus_one_list = map(lambda x: x**2 + 1, some_list) >> >> I realise that this is about understanding lambda, but it's worth noting >> in passing that we tend to writ

Re: I am new to python. I have a few questions coming from an armature!

2016-08-16 Thread Jussi Piitulainen
Lawrence D’Oliveiro writes: > On Tuesday, August 16, 2016 at 6:53:24 PM UTC+12, Jussi Piitulainen wrote: >> Lawrence D’Oliveiro writes: >> >>> Why could this difference be important? >> >> Different comprehensions (pun!) and performance characteristics.

Re: I am new to python. I have a few questions coming from an armature!

2016-08-17 Thread Jussi Piitulainen
BartC writes: > On 17/08/2016 07:39, Steven D'Aprano wrote: >> Rather than ask why Python uses `trueval if cond else falseval`, you >> should ask why C uses `cond ? trueval : falseval`. Is that documented >> anywhere? > > I'm not fond of C's a ? b : c but the principle is sound. I generally [- -]

Re: I am new to python. I have a few questions coming from an armature!

2016-08-17 Thread Jussi Piitulainen
MRAB writes: > On 2016-08-17 12:24, Jussi Piitulainen wrote: >> BartC writes: >> >>> On 17/08/2016 07:39, Steven D'Aprano wrote: >>>> Rather than ask why Python uses `trueval if cond else falseval`, you >>>> should ask why C uses `cond ?

Re: I am new to python. I have a few questions coming from an armature!

2016-08-17 Thread Jussi Piitulainen
Ben Bacarisse writes: > Jussi Piitulainen writes: > >> BartC writes: >> >>> On 17/08/2016 07:39, Steven D'Aprano wrote: >>>> Rather than ask why Python uses `trueval if cond else falseval`, you >>>> should ask why C uses `cond ? trueval :

Re: I am new to python. I have a few questions coming from an armature!

2016-08-18 Thread Jussi Piitulainen
Terry Reedy writes: > On 8/17/2016 2:39 AM, Steven D'Aprano wrote: [- -] >> Because the C syntax is horrifically ugly, whereas the Python syntax >> is very close to real English syntax. >> >> "What will you do tonight?" >> >> "Go to the movies, if I finish work on time, otherwise just go home." >

Re: I am new to python. I have a few questions coming from an armature!

2016-08-18 Thread Jussi Piitulainen
Lawrence D’Oliveiro writes: > On Thursday, August 18, 2016 at 7:22:50 PM UTC+12, Jussi Piitulainen wrote: >> But please consider calling them conditional expressions. > > And don’t forget switch-expressions, or case-expressions, as some > other advanced languages have had. Which

Re: I am new to python. I have a few questions coming from an armature!

2016-08-18 Thread Jussi Piitulainen
Marko Rauhamaa writes: > Jussi Piitulainen wrote: > >> That looks a bit funny if the "keyword" does not look like a word, >> but then programming languages do look funny, so why not: >> >>(c ? t : e) # ?-expression >> >>(c ->

Re: I am new to python. I have a few questions coming from an armature!

2016-08-18 Thread Jussi Piitulainen
MRAB writes: > On 2016-08-18 10:46, Jussi Piitulainen wrote: >> Marko Rauhamaa writes: >> >>> Jussi Piitulainen wrote: >>> >>>> That looks a bit funny if the "keyword" does not look like a word, >>>> but then progr

Re: a *= b not equivalent to a = a*b

2016-08-25 Thread Jussi Piitulainen
mlz writes: > I've been playing with the binomial function, and found that in the > below code, rs *= x does not behave the same way as rs = rs * x. When > I set FAIL to True, I get a different result. Both results are below. > > I had read that the two were equivalent. What am I missing? You do

Re: a *= b not equivalent to a = a*b

2016-08-26 Thread Jussi Piitulainen
mlzarathus...@gmail.com writes: > Yes, I just worked that out. It's the integer math that's the problem. > > I guess this has been fixed in python 3 [- -] Note that division in Python 3 produces approximate results (floating point numbers). This may or may not be what you want in this exercise. I

Re: a *= b not equivalent to a = a*b

2016-08-26 Thread Jussi Piitulainen
mlz writes: > It's true that a*(b/c) yields fractions which would probably accrue > accuracy errors depending on how those values are implemented. For > example, it is possible to represent 1/3 internally as two numbers, > numerator and denominator, thus avoiding the repeating decimal (or > binima

Re: What's the best way to minimize the need of run time checks?

2016-08-27 Thread Jussi Piitulainen
Chris Angelico writes: > On Sun, Aug 28, 2016 at 2:30 PM, Steve D'Aprano wrote: >> But in dynamic typing, the type information isn't associated with the >> name "x", but with the value 1 currently assigned to it. Change the >> assignment, and the type changes. As a consequence, it is necessary >>

Re: What's the best way to minimize the need of run time checks?

2016-08-28 Thread Jussi Piitulainen
Chris Angelico writes: > On Sun, Aug 28, 2016 at 4:13 PM, Jussi Piitulainen wrote: >>> This is where I'm less sure. Sometimes a variable's type should be >>> broader than just one concrete type - for instance, a variable might >>> hold 1 over here, and 1.

Re: Extend unicodedata with a name/pattern/regex search for character entity references?

2016-09-03 Thread Jussi Piitulainen
Chris Angelico writes: > On Sun, Sep 4, 2016 at 12:49 PM, Steve D'Aprano > wrote: >> On Sun, 4 Sep 2016 12:19 pm, Chris Angelico wrote: >> >> [...] Please either comply, or give up your stupid and pointless obsession with trying to be the Internet Police for something that isn't even a

Re: Would like some thoughts on a grouped iterator.

2016-09-05 Thread Jussi Piitulainen
Antoon Pardon writes: > I need an interator that takes an already existing iterator and > divides it into subiterators of items belonging together. > > For instance take the following class, wich would check whether > the argument is greater or equal to the previous argument. > > class upchecker:

Re: Would like some thoughts on a grouped iterator.

2016-09-05 Thread Jussi Piitulainen
Peter Otten writes: > Jussi Piitulainen wrote: [- -] >> while more: >> yield gp() [- -] > As usual I couldn't stop and came up with something very similar: [- -] > while more: > g = group() > yield g > for _ in g: p

Re: What you can do about legalese nonsense on email (was: How to split value where is comma ?)

2016-09-08 Thread Jussi Piitulainen
Grant Edwards writes: > On 2016-09-08, Joaquin Alzola wrote: > >> Basically what all comes down is to complain. I wonder if in a >> company of 80,000 people I will manage to change that behaviour. > > Perhaps others have complained. If enough people complain, maybe > they'll do something. > > Aft

Re: How to extend a tuple of tuples?

2016-09-09 Thread Jussi Piitulainen
Ben Finney writes: > Frank Millman writes: > >> Assume you have a tuple of tuples - >> >> a = ((1, 2), (3, 4)) >> >> You want to add a new tuple to it, so that it becomes > > As you acknowledge, the tuple ‘a’ can't become anything else. Instead, > you need to create a different value. > >> The obv

  1   2   3   4   5   6   7   >