Re: Unpaking Tuple

2012-10-08 Thread Dave Angel
On 10/09/2012 02:07 AM, Bob Martin wrote: > in 682592 20121008 232126 "Prasad, Ramit" wrote: >> Thomas Bach wrote:=0D=0A> Hi there,=0D=0A> =0D=0A> On Sat, Oct 06, 2012 at = >> 03:08:38PM +, Steven D'Aprano wrote:=0D=0A> >=0D=0A> > my_tuple

Re: RE: Unpaking Tuple

2012-10-08 Thread Bob Martin
in 682592 20121008 232126 "Prasad, Ramit" wrote: >Thomas Bach wrote:=0D=0A> Hi there,=0D=0A> =0D=0A> On Sat, Oct 06, 2012 at = >03:08:38PM +, Steven D'Aprano wrote:=0D=0A> >=0D=0A> > my_tuple =3D my_= >tuple[:4]=0D=0A> > a,b,c,d =3D my_tuple

Re: wordnet semantic similarity: how to refer to elements of a pair in a list? can we sort dictionary according to the value?

2012-10-08 Thread alex23
On Oct 9, 2:16 pm, Token Type wrote: > When I try my above codes, what puzzles me is that when > the data in the dictionary increase, some data become > missing in the sorted result. Quite odd. In the pairs, > we have {'journey':'voyage'} but in the sorted result no ( > 'journey-voyage',0.25) > >

Re: wordnet semantic similarity: how to refer to elements of a pair in a list? can we sort dictionary according to the value?

2012-10-08 Thread Token Type
Thanks indeed for all your suggestions. When I try my above codes, what puzzles me is that when the data in the dictionary increase, some data become missing in the sorted result. Quite odd. In the pairs, we have {'journey':'voyage'} but in the sorted result no ('journey-voyage',0.25), which did

Re: wordnet semantic similarity: how to refer to elements of a pair in a list? can we sort dictionary according to the value?

2012-10-08 Thread alex23
On Oct 9, 1:13 pm, Token Type wrote: > yes, thanks all your tips. I did try sorted with itemgetter. > However, the sorted results are same as follows whether I > set reverse=True or reverse= False. Isn't it strange? Thanks. That's because you're sorting each entry individually, not the entire res

Re: wordnet semantic similarity: how to refer to elements of a pair in a list? can we sort dictionary according to the value?

2012-10-08 Thread Ian Kelly
On Mon, Oct 8, 2012 at 9:13 PM, Token Type wrote: > yes, thanks all your tips. I did try sorted with itemgetter. However, the > sorted results are same as follows whether I set reverse=True or reverse= > False. Isn't it strange? Thanks. First of all, "sorted" does not sort the list in place as

Re: wordnet semantic similarity: how to refer to elements of a pair in a list? can we sort dictionary according to the value?

2012-10-08 Thread Token Type
Dear all, the problem has been solved as follows. Thanks anyway: >>> import nltk >>> from nltk.corpus import wordnet as wn >>> pairs = {'car':'automobile', 'gem':'jewel', 'journey':'voyage'} >>> list_simi=[] >>> for key in pairs: word1 = wn.synset(str(key) + '.n.01') word2 = wn.syn

Re: Insert item before each element of a list

2012-10-08 Thread alex23
On Oct 9, 12:06 pm, Roy Smith wrote: > I'm going to go with this one.  I think people tend to over-abuse list > comprehensions. I weep whenever I find `_ = [...]` in other people's code. -- http://mail.python.org/mailman/listinfo/python-list

Re: wordnet semantic similarity: how to refer to elements of a pair in a list? can we sort dictionary according to the value?

2012-10-08 Thread Token Type
yes, thanks all your tips. I did try sorted with itemgetter. However, the sorted results are same as follows whether I set reverse=True or reverse= False. Isn't it strange? Thanks. >>> import nltk >>> from nltk.corpus import wordnet as wn >>> pairs = {'car':'automobile', 'gem':'jewel', 'journey'

Re: Insert item before each element of a list

2012-10-08 Thread rusi
On Oct 9, 7:34 am, rusi wrote: > How about a 2-paren version? > > >>> x = [1,2,3] > >>> reduce(operator.add,  [['insert', a] for a in x]) > > ['insert', 1, 'insert', 2, 'insert', 3] Or if one prefers the different parens on the other side: >>> reduce(operator.add, (['insert', a] for a in x)) ['i

Re: Insert item before each element of a list

2012-10-08 Thread rusi
On Oct 9, 7:06 am, Roy Smith wrote: > In article , >  Terry Reedy wrote: > > > > > > > > > > > On 10/8/2012 3:28 PM, mooremath...@gmail.com wrote: > > > What's the best way to accomplish this?  Am I over-complicating it?  My > > > gut > > > feeling is there is a better way than the following: >

Re: To get the accurate value of 1 - 0.999999999999999 ,how to implement the python algorithm ?

2012-10-08 Thread Dave Angel
On 10/08/2012 09:45 PM, Terry Reedy wrote: > On 10/8/2012 11:13 AM, Dave Angel wrote: > >>> Isn't it true, though, that Python 3.3 has a completely new >>> implementation of decimal that largely removes this disadvantage? > >> I wouldn't know, I'm on 3.2. However, I sincerely doubt if it's within

Re: Insert item before each element of a list

2012-10-08 Thread Roy Smith
In article , Terry Reedy wrote: > On 10/8/2012 3:28 PM, mooremath...@gmail.com wrote: > > What's the best way to accomplish this? Am I over-complicating it? My gut > > feeling is there is a better way than the following: > > > import itertools > x = [1, 2, 3] > y = list(itertoo

Re: Insert item before each element of a list

2012-10-08 Thread Terry Reedy
On 10/8/2012 3:28 PM, mooremath...@gmail.com wrote: What's the best way to accomplish this? Am I over-complicating it? My gut feeling is there is a better way than the following: import itertools x = [1, 2, 3] y = list(itertools.chain.from_iterable(('insertme', x[i]) for i in range(len(x)))

Re: To get the accurate value of 1 - 0.999999999999999 ,how to implement the python algorithm ?

2012-10-08 Thread Terry Reedy
On 10/8/2012 11:13 AM, Dave Angel wrote: Isn't it true, though, that Python 3.3 has a completely new implementation of decimal that largely removes this disadvantage? I wouldn't know, I'm on 3.2. However, I sincerely doubt if it's within a factor of 100 of the speed of the binary float, at l

Re: Insert item before each element of a list

2012-10-08 Thread Alex
mooremath...@gmail.com wrote: > What's the best way to accomplish this? Am I over-complicating it? > My gut feeling is there is a better way than the following: > > >>> import itertools > >>> x = [1, 2, 3] > >>> y = list(itertools.chain.from_iterable(('insertme', x[i]) for i > in range(len(x

Re: Plumbum (Shell Combinators) hits v1.0

2012-10-08 Thread Amirouche Boubekki
2012/10/6 Tomer Filiba > http://plumbum.readthedocs.org/en/latest/index.html > > Ever wished the wrist-handiness of shell scripts be put into a real > programming language? Say hello to Plumbum Shell Combinators. Plumbum > (Latin for lead, which was used to create pipes back in the day) is a smal

RE: Unpaking Tuple

2012-10-08 Thread Prasad, Ramit
Thomas Bach wrote: > Hi there, > > On Sat, Oct 06, 2012 at 03:08:38PM +, Steven D'Aprano wrote: > > > > my_tuple = my_tuple[:4] > > a,b,c,d = my_tuple if len(my_tuple) == 4 else (my_tuple + (None,)*4)[:4] > > > > Are you sure this works as you expect? I just stumbled over the following: > >

Re: Insert item before each element of a list

2012-10-08 Thread Nobody
On Mon, 08 Oct 2012 12:28:43 -0700, mooremathewl wrote: import itertools x = [1, 2, 3] y = list(itertools.chain.from_iterable(('insertme', x[i]) for i in range(len(x y > ['insertme', 1, 'insertme', 2, 'insertme', 3] >>> [i for j in [1,2,3] for i in ('insertme', j)]

Re: Unpaking Tuple

2012-10-08 Thread Joshua Landau
On 8 October 2012 22:45, Thomas Bach wrote: > Hi there, > > On Sat, Oct 06, 2012 at 03:08:38PM +, Steven D'Aprano wrote: > > > > my_tuple = my_tuple[:4] > > a,b,c,d = my_tuple if len(my_tuple) == 4 else (my_tuple + (None,)*4)[:4] > > > > Are you sure this works as you expect? I just stumbled

Re: Insert item before each element of a list

2012-10-08 Thread Paul Rubin
mooremath...@gmail.com writes: x = [1, 2, 3] .. y > ['insertme', 1, 'insertme', 2, 'insertme', 3] def ix(prefix, x): for a in x: yield prefix yield a y = list(ix('insertme', x)) from itertools import * y = list(chain.from_iterable(izip(repeat('insertme'

RE: Insert item before each element of a list

2012-10-08 Thread Prasad, Ramit
Agon Hajdari wrote: > On 10/08/2012 11:15 PM, Prasad, Ramit wrote: > > Agon Hajdari wrote: > >> > >> On 10/08/2012 09:45 PM, Chris Kaynor wrote: > >>> [('insertme', i) for i in x] > >> > >> This is not enough, you have to merge it afterwards. > > > > Why do you say that? It seems to work just fine

Re: Unpaking Tuple

2012-10-08 Thread Thomas Bach
Hi there, On Sat, Oct 06, 2012 at 03:08:38PM +, Steven D'Aprano wrote: > > my_tuple = my_tuple[:4] > a,b,c,d = my_tuple if len(my_tuple) == 4 else (my_tuple + (None,)*4)[:4] > Are you sure this works as you expect? I just stumbled over the following: $ python Python 3.2.3 (default, Jun 25

Re: Insert item before each element of a list

2012-10-08 Thread Agon Hajdari
On 10/08/2012 11:15 PM, Prasad, Ramit wrote: > Agon Hajdari wrote: >> Sent: Monday, October 08, 2012 3:12 PM >> To: python-list@python.org >> Subject: Re: Insert item before each element of a list >> >> On 10/08/2012 09:45 PM, Chris Kaynor wrote: >>> [('insertme', i) for i in x] >> >> This is not e

RE: Insert item before each element of a list

2012-10-08 Thread Prasad, Ramit
Agon Hajdari wrote: > Sent: Monday, October 08, 2012 3:12 PM > To: python-list@python.org > Subject: Re: Insert item before each element of a list > > On 10/08/2012 09:45 PM, Chris Kaynor wrote: > > [('insertme', i) for i in x] > > This is not enough, you have to merge it afterwards. Why do you

Re: Insert item before each element of a list

2012-10-08 Thread Peter Otten
mooremath...@gmail.com wrote: > What's the best way to accomplish this? Am I over-complicating it? My > gut feeling is there is a better way than the following: > import itertools x = [1, 2, 3] y = list(itertools.chain.from_iterable(('insertme', x[i]) for i in range(len(x)))

Re: Insert item before each element of a list

2012-10-08 Thread Agon Hajdari
On 10/08/2012 09:45 PM, Chris Kaynor wrote: > [('insertme', i) for i in x] This is not enough, you have to merge it afterwards. y = [item for tup in y for item in tup] -- http://mail.python.org/mailman/listinfo/python-list

Re: Insert item before each element of a list

2012-10-08 Thread Ian Kelly
On Mon, Oct 8, 2012 at 1:52 PM, Joshua Landau wrote: > But it's not far. I wouldn't use Ian Kelly's method (no offence), because of > len(x): it's less compatible with iterables. Others have ninja'd me with > good comments, too. That's fair, I probably wouldn't use it either. It points to a poss

Re: Insert item before each element of a list

2012-10-08 Thread Joshua Landau
On 8 October 2012 20:28, wrote: > What's the best way to accomplish this? Am I over-complicating it? My > gut feeling is there is a better way than the following: > > >>> import itertools > >>> x = [1, 2, 3] > >>> y = list(itertools.chain.from_iterable(('insertme', x[i]) for i in > range(len(x)

Re: Insert item before each element of a list

2012-10-08 Thread MRAB
On 2012-10-08 20:28, mooremath...@gmail.com wrote: What's the best way to accomplish this? Am I over-complicating it? My gut feeling is there is a better way than the following: import itertools x = [1, 2, 3] y = list(itertools.chain.from_iterable(('insertme', x[i]) for i in range(len(x

Re: Insert item before each element of a list

2012-10-08 Thread Chris Kaynor
On Mon, Oct 8, 2012 at 12:28 PM, wrote: > What's the best way to accomplish this? Am I over-complicating it? My > gut feeling is there is a better way than the following: > > >>> import itertools > >>> x = [1, 2, 3] > >>> y = list(itertools.chain.from_iterable(('insertme', x[i]) for i in > rang

Re: Insert item before each element of a list

2012-10-08 Thread Ian Kelly
On Mon, Oct 8, 2012 at 1:28 PM, wrote: > What's the best way to accomplish this? Am I over-complicating it? My gut > feeling is there is a better way than the following: > import itertools x = [1, 2, 3] y = list(itertools.chain.from_iterable(('insertme', x[i]) for i in ran

Insert item before each element of a list

2012-10-08 Thread mooremathewl
What's the best way to accomplish this? Am I over-complicating it? My gut feeling is there is a better way than the following: >>> import itertools >>> x = [1, 2, 3] >>> y = list(itertools.chain.from_iterable(('insertme', x[i]) for i in >>> range(len(x >>> y ['insertme', 1, 'insertme', 2,

Re: how to build Object for List data

2012-10-08 Thread Joel Goldstick
On Mon, Oct 8, 2012 at 2:50 PM, Laszlo Nagy wrote: >> >> Seq validation >> 1 Program3,1,3,4 # max(F1,F3) to F4 >> .. >> n >> How to using python to Read the text file, Build the data as object >> class ? > > Open the file using the open() command. Then iterate over the lines within

Re: how to build Object for List data

2012-10-08 Thread Laszlo Nagy
Seq validation 1 Program3,1,3,4 # max(F1,F3) to F4 .. n How to using python to Read the text file, Build the data as object class ? Open the file using the open() command. Then iterate over the lines within a stateful algorithm that parses the lines with regular expressions. Wh

how to build Object for List data

2012-10-08 Thread moonhkt
Hi All I have Data call FM01. Each format have F1.. F50 Fields. And Global Program G1..Gn. The format like below as text file FM01 Fld #FieldValidation 1F1 N/A 2F2 N/A 3F3 Program1,1,2,3 # Add F1 and F2 value to F3 4F4

Re: To get the accurate value of 1 - 0.999999999999999 ,how to implement the python algorithm ?

2012-10-08 Thread Ulrich Eckhardt
Am 08.10.2012 16:07, schrieb iMath: To get the accurate value of 1 - 0.999 ,how to implement the python algorithm ? Algorithms are generally language-agnostic, so what is your question BTW ,Windows’s calculator get the accurate value ,anyone who knows how to implement it ? You

Re: To get the accurate value of 1 - 0.999999999999999 ,how to implement the python algorithm ?

2012-10-08 Thread Chris Angelico
On Tue, Oct 9, 2012 at 2:13 AM, Dave Angel wrote: > On 10/08/2012 11:00 AM, Chris Angelico wrote: >> On Tue, Oct 9, 2012 at 1:48 AM, Dave Angel wrote: >>> The Decimal class has the disadvantage that it's tons slower on any modern >>> machine I know of... >> Isn't it true, though, that Python 3.3

Re: To get the accurate value of 1 - 0.999999999999999 ,how to implement the python algorithm ?

2012-10-08 Thread Dave Angel
On 10/08/2012 11:00 AM, Chris Angelico wrote: > On Tue, Oct 9, 2012 at 1:48 AM, Dave Angel wrote: >> import decimal >> a = decimal.Decimal(4.3) >> print(a) >> >> 5.0996447286321199499070644378662109375 > Ah, the delights of copy-paste :) > >> The Decimal class has the disadvantage that

Re: To get the accurate value of 1 - 0.999999999999999 ,how to implement the python algorithm ?

2012-10-08 Thread Chris Angelico
On Tue, Oct 9, 2012 at 1:48 AM, Dave Angel wrote: > import decimal > a = decimal.Decimal(4.3) > print(a) > > 5.0996447286321199499070644378662109375 Ah, the delights of copy-paste :) > The Decimal class has the disadvantage that it's tons slower on any modern > machine I know of...

Re: Question on Python Split

2012-10-08 Thread subhabangalore
On Monday, October 8, 2012 1:00:52 AM UTC+5:30, subhaba...@gmail.com wrote: > Dear Group, > > > > Suppose I have a string as, > > > > "Project Gutenberg has 36000 free ebooks for Kindle Android iPad iPhone." > > > > I am terming it as, > > > > str1= "Project Gutenberg has 36000 free eb

Re: To get the accurate value of 1 - 0.999999999999999 ,how to implement the python algorithm ?

2012-10-08 Thread Dave Angel
On 10/08/2012 10:07 AM, iMath wrote: > To get the accurate value of 1 - 0.999 ,how to implement the > python algorithm ? > BTW ,Windows’s calculator get the accurate value ,anyone who knows how to > implement it ? Windows calculator is an application, not a programming language. Lik

Re: How to control the internet explorer?

2012-10-08 Thread yujian
Thank you On Mon, Oct 8, 2012 at 11:37 AM, alex23 wrote: > On Oct 8, 1:03 pm, yujian wrote: > > I want to save all the URLs in current opened windows, and then close > > all the windows. > > Try mechanize or Selenium. > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail

[ANN] pylint 0.26 / logilab-astng 0.24.1

2012-10-08 Thread Sylvain Thénault
Hi all, I'm very pleased to announce new releases of Pylint and underlying ASTNG library, respectivly 0.26 and 0.24.1. The great news is that both bring a lot of new features and some bug fixes, mostly provided by the community effort. We're still trying to make it easier to contribute on our fre

To get the accurate value of 1 - 0.999999999999999 ,how to implement the python algorithm ?

2012-10-08 Thread iMath
To get the accurate value of 1 - 0.999 ,how to implement the python algorithm ? BTW ,Windows’s calculator get the accurate value ,anyone who knows how to implement it ? -- http://mail.python.org/mailman/listinfo/python-list

Re: Reading properties file in Python, except using ConfigParser()

2012-10-08 Thread justmailharsh
On Friday, October 5, 2012 5:03:01 PM UTC+5:30, Günther Dietrich wrote: > justmailha...@gmail.com wrote: > > > > >How to read properties file in Python? I found ConfigParser() but it has a > > >'section' limitation, so looking for other alternatives. > > > > Have a look at PyYAML. > > >