Re: Dynamically swapping between two algorithms

2014-09-25 Thread Ethan Furman
On 09/23/2014 07:48 AM, Steven D'Aprano wrote: alas, the CUTOVER point is likely to be machine-dependent. Take it as a given that inserting a fixed CUTOVER point into the source code (say, ``CUTOVER = 123456``) is not likely to be very effective, and dynamically calculating it at import time is

Re: Dynamically swapping between two algorithms

2014-09-25 Thread Cameron Simpson
On 24Sep2014 00:48, Steven D'Aprano wrote: I have a certain calculation which can be performed two radically different ways. With the first algorithm, let's call it SHORT, performance is very fast for small values of the argument, but terrible for large values. For the second algorithm, LARGE,

Re: Dynamically swapping between two algorithms

2014-09-24 Thread dieter
Steven D'Aprano writes: > ... > *If* Python was a different language, I would spawn two threads, one using > SHORT and the other using LARGE, then which ever completes first, I'd just > kill the other. Alas, this won't work because (1) the GIL The GIL does not prevent this scenario. The two threa

Re: Dynamically swapping between two algorithms

2014-09-23 Thread C Smith
wn two threads, one using >> SHORT and the other using LARGE, then which ever completes first, I'd just >> kill the other. Alas, this won't work because (1) the GIL and (2) you >> cannot forcibly kill threads, only ask them to die and hope they listen. >> >

Re: Dynamically swapping between two algorithms

2014-09-23 Thread Terry Reedy
seeking other ideas for dynamically swapping between the two algorithms, based on runtime information. Any thoughts? (1) I can't tell in advance how many loops I will make. (2) Both SHORT and LARGE get slower as the size of their argument increases. This is unavoidable due to the nature of th

Re: Dynamically swapping between two algorithms

2014-09-23 Thread MRAB
seeking other ideas for dynamically swapping between the two algorithms, based on runtime information. Any thoughts? (1) I can't tell in advance how many loops I will make. (2) Both SHORT and LARGE get slower as the size of their argument increases. This is unavoidable due to the nature of the pr

Re: Dynamically swapping between two algorithms

2014-09-23 Thread emile
t kill the other. Alas, this won't work because (1) the GIL and (2) you cannot forcibly kill threads, only ask them to die and hope they listen. I am seeking other ideas for dynamically swapping between the two algorithms, based on runtime information. Any thoughts? (1) I can't tell in a

Re: Dynamically swapping between two algorithms

2014-09-23 Thread Chris Angelico
On Wed, Sep 24, 2014 at 12:48 AM, Steven D'Aprano wrote: > (3) SHORT starts off relatively speedy, significantly faster than LARGE for > the first few tens of thousands of loops. I'm not talking about trivial > micro-optimizations here, I'm talking about the difference between 0.1 > second for SHO

Dynamically swapping between two algorithms

2014-09-23 Thread Steven D'Aprano
ng SHORT and the other using LARGE, then which ever completes first, I'd just kill the other. Alas, this won't work because (1) the GIL and (2) you cannot forcibly kill threads, only ask them to die and hope they listen. I am seeking other ideas for dynamically swapping between the two al

Re: memory management - avoid swapping/paging

2010-10-22 Thread Jon Clements
ocking to processes owned by > root or with the CAP_IPC_LOCK capability. The "man" and "help" ref's are much appreciated. It's narrowed my search space. > Also, locking a specific region of memory won't necessarily help if the > program code and stack are

Re: memory management - avoid swapping/paging

2010-10-21 Thread Nobody
o lock memory is controlled via resource limits (see "man 2 setrlimit", "help ulimit" and "man 5 limits.conf"). Earlier versions limit memory locking to processes owned by root or with the CAP_IPC_LOCK capability. Also, locking a specific region of memory won't nec

Re: memory management - avoid swapping/paging

2010-10-21 Thread Alain Ketterlin
Jon Clements writes: > Is there a cross-platform way using Python to guarantee that an object > will never be swapped/paged to disk? I'll be honest and say I'm really > not sure if this is a particular language question or rather specific > to an OS. > > Under linux it appears I could create a r

memory management - avoid swapping/paging

2010-10-21 Thread Jon Clements
Hi all, Is there a cross-platform way using Python to guarantee that an object will never be swapped/paged to disk? I'll be honest and say I'm really not sure if this is a particular language question or rather specific to an OS. Under linux it appears I could create a ramfs and mmap a file under

Re: Swapping Content of Two Dictionaries.

2010-03-17 Thread Steven D'Aprano
On Wed, 17 Mar 2010 13:34:51 +0100, Peter Otten wrote: > Hatem Oraby wrote: > >> Hello, I want to swap the content of two dictionaries, the obvious way >> to do it is: >> a = {1:"I'am A"} >> b = {2:"I'm B"} >> temp = a >> a = b >> b = temp > > That can be simplified to > > a, b = b, a > > and

Re: Swapping Content of Two Dictionaries.

2010-03-17 Thread Stefan Behnel
Hatem Oraby, 17.03.2010 12:26: However, consider the case in which the dictionary we are referencing lives in another module: #external.py # #a = {1:"I'am A} import external temp = external.a external.a = b b = temp Looks like the interface of your module is broken. It shouldn't export the tw

Re: Swapping Content of Two Dictionaries.

2010-03-17 Thread Peter Otten
"b": 2} >>> b = {"b": 3, "c": 4} >>> t = a.copy() >>> a.clear() >>> a.update(b) >>> b.clear() >>> b.update(t) >>> a {'c': 4, 'b': 3} >>> b {'a': 1, 'b': 2} >

Swapping Content of Two Dictionaries.

2010-03-17 Thread Hatem Oraby
Hello, I want to swap the content of two dictionaries, the obvious way to do it is: a = {1:"I'am A"} b = {2:"I'm B"} temp = a a = b b = temp However, consider the case in which the dictionary we are referencing lives in another module: #external.py # #a = {1:"I'am A} import external temp = extern

Re: Swapping superclass from a module

2009-05-17 Thread Terry Reedy
Peter Otten wrote: Terry Reedy wrote: If the names of superclasses is resolved when classes are instantiated, the patching is easy. If, as I would suspect, the names are resolved when the classes are created, before the module becomes available to the importing code, then much more careful a

Re: Swapping superclass from a module

2009-05-17 Thread Emanuele D'Arrigo
Wow, thank you all. Lots of ideas and things to try! I wish I knew which one is going to work best. The module I'm trying to (monkey!) patch is pxdom, and as it is a bit long (5700 lines of code in one file!) I'm not quite sure if the simplest patching method will work or the more complicated o

Re: Swapping superclass from a module

2009-05-17 Thread Peter Otten
Terry Reedy wrote: > Steven D'Aprano wrote: >> On Sat, 16 May 2009 09:55:39 -0700, Emanuele D'Arrigo wrote: >> >>> Hi everybody, >>> >>> let's assume I have a module with loads of classes inheriting from one >>> class, from the same module, i.e.: >> [...] >>> Now, let's also assume that myFile.py

Re: Swapping superclass from a module

2009-05-17 Thread Michele Simionato
Try this: class Base(object): pass class C(Base): pass class NewBase(object): pass C.__bases__ = (NewBase,) help(C) -- http://mail.python.org/mailman/listinfo/python-list

Re: Swapping superclass from a module

2009-05-16 Thread Terry Reedy
Steven D'Aprano wrote: On Sat, 16 May 2009 09:55:39 -0700, Emanuele D'Arrigo wrote: Hi everybody, let's assume I have a module with loads of classes inheriting from one class, from the same module, i.e.: [...] Now, let's also assume that myFile.py cannot be changed or it's impractical to do

Re: Swapping superclass from a module

2009-05-16 Thread Steven D'Aprano
On Sat, 16 May 2009 09:55:39 -0700, Emanuele D'Arrigo wrote: > Hi everybody, > > let's assume I have a module with loads of classes inheriting from one > class, from the same module, i.e.: [...] > Now, let's also assume that myFile.py cannot be changed or it's > impractical to do so. Is there a w

Re: Swapping superclass from a module

2009-05-16 Thread Arnaud Delobelle
"Emanuele D'Arrigo" writes: > On May 16, 8:17 pm, Arnaud Delobelle wrote: >> # Insert Wedge into each subclass of modfoo.Base >> for subclass in modfoo.Base.__subclasses__(): >>     if subclass.__module__ != 'modfoo': continue >>     attrs = dict(item for item in subclass.__dict__.items() >>    

Re: Swapping superclass from a module

2009-05-16 Thread Emanuele D'Arrigo
On May 16, 8:17 pm, Arnaud Delobelle wrote: > # Insert Wedge into each subclass of modfoo.Base > for subclass in modfoo.Base.__subclasses__(): >     if subclass.__module__ != 'modfoo': continue >     attrs = dict(item for item in subclass.__dict__.items() >                       if item[0][:2] !=

Re: Swapping superclass from a module

2009-05-16 Thread Arnaud Delobelle
"Emanuele D'Arrigo" writes: > Hi everybody, > > let's assume I have a module with loads of classes inheriting from one > class, from the same module, i.e.: > > ## myFile.py > class SuperClass(object) > class SubClass1(SuperClass) > class SubClass2(SuperClass) > class SubClass3(SuperClass) > > In

Swapping superclass from a module

2009-05-16 Thread Emanuele D'Arrigo
Hi everybody, let's assume I have a module with loads of classes inheriting from one class, from the same module, i.e.: ## myFile.py class SuperClass(object) class SubClass1(SuperClass) class SubClass2(SuperClass) class SubClass3(SuperClass) In a separate file I also have: ## myOtherFile.py cla

Re: sharing/swapping items between lists

2009-04-15 Thread MRAB
samwyse wrote: On Apr 15, 8:13 am, Aaron Brady wrote: On Apr 15, 6:57 am, samwyse wrote: Here's my idea: generate all possible pairs: import itertools players = [chr(c) for c in xrange(ord('a'),ord('z')+1)] all_pairs = list(itertools.combinations(players,2)) partition the list: def choos

Re: sharing/swapping items between lists

2009-04-15 Thread Aaron Brady
On Apr 15, 11:29 am, samwyse wrote: > On Apr 15, 8:56 am, Aaron Brady wrote: > > > > > The randomizing solution isn't quite suitable for 16 teams.  With 5 > > teams/1 court, and 5 teams/2 courts, 6 teams/2 courts, the solution > > comes within seconds.  For 7 teams/3 courts, the solution takes a

Re: sharing/swapping items between lists

2009-04-15 Thread samwyse
On Apr 15, 8:56 am, Aaron Brady wrote: > > The randomizing solution isn't quite suitable for 16 teams.  With 5 > teams/1 court, and 5 teams/2 courts, 6 teams/2 courts, the solution > comes within seconds.  For 7 teams/3 courts, the solution takes a few > minutes. 7 teams/3 courts is the same as 8

Re: sharing/swapping items between lists

2009-04-15 Thread samwyse
On Apr 15, 8:13 am, Aaron Brady wrote: > On Apr 15, 6:57 am, samwyse wrote: > > > Here's my idea: generate all possible pairs: > > > >>> import itertools > > >>> players = [chr(c) for c in xrange(ord('a'),ord('z')+1)] > > >>> all_pairs = list(itertools.combinations(players,2)) > > > partition th

Re: sharing/swapping items between lists

2009-04-15 Thread Aaron Brady
On Apr 14, 9:45 pm, Ross wrote: > On Apr 14, 7:18 pm, Aaron Brady wrote: > > > > > On Apr 14, 7:01 pm, Aaron Brady wrote: > > > > On Apr 14, 12:37 pm, Ross wrote: > > > > > On Apr 14, 10:34 am, Ross wrote: > > > > > > On Apr 14, 5:57 am, a...@pythoncraft.com (Aahz) wrote: > > > > > > > In arti

Re: sharing/swapping items between lists

2009-04-15 Thread Aaron Brady
On Apr 15, 6:57 am, samwyse wrote: > On Apr 14, 7:01 pm, Aaron Brady wrote: > > > Here is an idea.  Create a list of all possible pairs, using > > itertools.combinations.  You'll notice everyone gets equal play time > > and equal time against each other on a pair-by-pair basis.  Then, call > > ra

Re: sharing/swapping items between lists

2009-04-15 Thread samwyse
On Apr 14, 7:01 pm, Aaron Brady wrote: > Here is an idea.  Create a list of all possible pairs, using > itertools.combinations.  You'll notice everyone gets equal play time > and equal time against each other on a pair-by-pair basis.  Then, call > random.shuffle until one player isn't playing on t

Re: sharing/swapping items between lists

2009-04-15 Thread Aaron Brady
On Apr 14, 9:45 pm, Ross wrote: > On Apr 14, 7:18 pm, Aaron Brady wrote: > > > > > On Apr 14, 7:01 pm, Aaron Brady wrote: > > > > On Apr 14, 12:37 pm, Ross wrote: > > > > > On Apr 14, 10:34 am, Ross wrote: > > > > > > On Apr 14, 5:57 am, a...@pythoncraft.com (Aahz) wrote: > > > > > > > In arti

Re: sharing/swapping items between lists

2009-04-14 Thread Ross
On Apr 14, 7:18 pm, Aaron Brady wrote: > On Apr 14, 7:01 pm, Aaron Brady wrote: > > > > > On Apr 14, 12:37 pm, Ross wrote: > > > > On Apr 14, 10:34 am, Ross wrote: > > > > > On Apr 14, 5:57 am, a...@pythoncraft.com (Aahz) wrote: > > > > > > In article > > > > > , > > > > > > Ross   wrote: > >

Re: sharing/swapping items between lists

2009-04-14 Thread Aaron Brady
On Apr 14, 7:01 pm, Aaron Brady wrote: > On Apr 14, 12:37 pm, Ross wrote: > > > > > On Apr 14, 10:34 am, Ross wrote: > > > > On Apr 14, 5:57 am, a...@pythoncraft.com (Aahz) wrote: > > > > > In article > > > > , > > > > > Ross   wrote: > > > > >On Apr 13, 9:08=A0am, a...@pythoncraft.com (Aahz) w

Re: sharing/swapping items between lists

2009-04-14 Thread Aaron Brady
On Apr 14, 12:37 pm, Ross wrote: > On Apr 14, 10:34 am, Ross wrote: > > > > > On Apr 14, 5:57 am, a...@pythoncraft.com (Aahz) wrote: > > > > In article > > > , > > > > Ross   wrote: > > > >On Apr 13, 9:08=A0am, a...@pythoncraft.com (Aahz) wrote: > > > >> In article > > > >> > > >com>, > > > >>

Re: sharing/swapping items between lists

2009-04-14 Thread Ross
On Apr 14, 10:34 am, Ross wrote: > On Apr 14, 5:57 am, a...@pythoncraft.com (Aahz) wrote: > > > > > In article > > , > > > Ross   wrote: > > >On Apr 13, 9:08=A0am, a...@pythoncraft.com (Aahz) wrote: > > >> In article > > >> > >com>, > > >> Ross =A0 wrote: > > > >>>I'm sorry...my example was pro

Re: sharing/swapping items between lists

2009-04-14 Thread Ross
On Apr 14, 5:57 am, a...@pythoncraft.com (Aahz) wrote: > In article , > > > > Ross   wrote: > >On Apr 13, 9:08=A0am, a...@pythoncraft.com (Aahz) wrote: > >> In article >com>, > >> Ross =A0 wrote: > > >>>I'm sorry...my example was probably a bad one. A better example of > >>>output I would like wou

Re: sharing/swapping items between lists

2009-04-14 Thread Aahz
In article , Ross wrote: >On Apr 13, 9:08=A0am, a...@pythoncraft.com (Aahz) wrote: >> In article com>, >> Ross =A0 wrote: >>> >>>I'm sorry...my example was probably a bad one. A better example of >>>output I would like would be something like [[1,2],[3,4],[5,6]] and >>>then for the leftovers list

Re: sharing/swapping items between lists

2009-04-14 Thread Aaron Brady
On Apr 13, 11:52 pm, Aaron Brady wrote: > On Apr 13, 10:04 am, Ross wrote: > > > > > On Apr 11, 1:10 pm, a...@pythoncraft.com (Aahz) wrote: > > > > In article > > > <4fd78ac3-ba83-456b-b768-3a0043548...@f19g2000vbf.googlegroups.com>, > > > > Ross   wrote: > > > > >I'm trying to design an iterato

Re: sharing/swapping items between lists

2009-04-13 Thread Aaron Brady
On Apr 13, 10:04 am, Ross wrote: > On Apr 11, 1:10 pm, a...@pythoncraft.com (Aahz) wrote: > > > > > In article > > <4fd78ac3-ba83-456b-b768-3a0043548...@f19g2000vbf.googlegroups.com>, > > > Ross   wrote: > > > >I'm trying to design an iterator that produces two lists. The first > > >list will be

Re: sharing/swapping items between lists

2009-04-13 Thread Ross
On Apr 13, 9:08 am, a...@pythoncraft.com (Aahz) wrote: > In article , > > Ross   wrote: > > >I'm sorry...my example was probably a bad one. A better example of > >output I would like would be something like [[1,2],[3,4],[5,6]] and > >then for the leftovers list [7,8,9,10 etc]. What I'm trying to do

Re: sharing/swapping items between lists

2009-04-13 Thread Aahz
In article , Ross wrote: > >I'm sorry...my example was probably a bad one. A better example of >output I would like would be something like [[1,2],[3,4],[5,6]] and >then for the leftovers list [7,8,9,10 etc]. What I'm trying to do is >produce some sort of round robin algorithm for tennis that is

Re: sharing/swapping items between lists

2009-04-13 Thread Ross
On Apr 11, 1:10 pm, a...@pythoncraft.com (Aahz) wrote: > In article > <4fd78ac3-ba83-456b-b768-3a0043548...@f19g2000vbf.googlegroups.com>, > > Ross   wrote: > > >I'm trying to design an iterator that produces two lists. The first > >list will be a list of unique pairings and the second will be a l

Re: sharing/swapping items between lists

2009-04-11 Thread Aahz
In article <4fd78ac3-ba83-456b-b768-3a0043548...@f19g2000vbf.googlegroups.com>, Ross wrote: > >I'm trying to design an iterator that produces two lists. The first >list will be a list of unique pairings and the second will be a list >of items that weren't used in the first list. After each round,

Re: sharing/swapping items between lists

2009-04-10 Thread Paul Rubin
Ross writes: > Can you guys suggest an approach to this problem...I'm trying to teach > myself python so an outline of how to approach this would probably be > more helpful to me than an explicit solution. I'll cry mercy if I > can't figure it out after your hints. Look at the "set" datatype. Th

sharing/swapping items between lists

2009-04-10 Thread Ross
I'm trying to design an iterator that produces two lists. The first list will be a list of unique pairings and the second will be a list of items that weren't used in the first list. After each round, the items that weren't used in the round before will get put back in and the second list will be p

Re: Swapping values of two variables

2009-01-30 Thread Grant Edwards
On 2009-01-31, Aahz wrote: >>But could the swapping be done using less extra memory than this? What >>is the minimum amount of extra memory required to exchange two 32-bit >>quantities? What would be the pseudocode that achieves this minimum? > > This looks like a homewo

Re: Swapping values of two variables

2009-01-30 Thread Aahz
In article , Eric Kang wrote: > >In python, I set: > >x=1 >y=3 > >z = x >x = y >y = z > > >This gave me 3 1, which are the values of x and y swapped. >The following would have given me the same result: >x, y = y, x > > > >But could the swappi

Re: Swapping values of two variables

2009-01-30 Thread Grant Edwards
> Grant Edwards wrote: > > On 2009-01-30, MRAB wrote: > > > >>> What is the minimum amount of extra memory required to exchange two > >>> 32-bit quantities? What would be the pseudocode that achieves this > >>> minimum? > >> x ^= y > >> y ^= x > >> x ^= y > >> > >> This is really only of use when

Re: Swapping values of two variables

2009-01-30 Thread Christian Heimes
Steven D'Aprano schrieb: > Ints in Python are *objects*, not 32-bit quantities. An int is 12 bytes > (96 bits) in size; a long will use as much memory as needed. If your > application needs to optimize a swap of two ints, then Python is probably > going to be much too memory-intensive for you.

Re: Swapping values of two variables

2009-01-30 Thread MRAB
Grant Edwards wrote: > On 2009-01-30, MRAB wrote: > >>> What is the minimum amount of extra memory required to exchange two >>> 32-bit quantities? What would be the pseudocode that achieves this >>> minimum? >> x ^= y >> y ^= x >> x ^= y >> >> This is really only of use when working in assembly l

Re: Swapping values of two variables

2009-01-29 Thread Steven D'Aprano
On Thu, 29 Jan 2009 21:23:48 -0800, Kottiyath wrote: > Is it possible to swap two floats without a variable? In Python? Sure. f = 1.23 g = 2.87 f, g = g, f This idiom is independent of the types of the objects: x = "hello world" y = [1, 2.0, None, "xyz", {}] x, y = y, x In other languages?

Re: Swapping values of two variables

2009-01-29 Thread tony . clarke5
= z > > >> This gave me 3 1, which are the values of x and y swapped. The > >> following would have given me the same result: x, y = y, x > > >> But could the swapping be done using less extra memory than this? What > >> is the minimum amount of extra memory

Re: Swapping values of two variables

2009-01-29 Thread Grant Edwards
On 2009-01-30, MRAB wrote: >> What is the minimum amount of extra memory required to exchange two >> 32-bit quantities? What would be the pseudocode that achieves this >> minimum? > > x ^= y > y ^= x > x ^= y > > This is really only of use when working in assembly language. And rarely then. ;)

Re: Swapping values of two variables

2009-01-29 Thread Kottiyath
= z > > >> This gave me 3 1, which are the values of x and y swapped. The > >> following would have given me the same result: x, y = y, x > > >> But could the swapping be done using less extra memory than this? What > >> is the minimum amount of extra memory

Re: Swapping values of two variables

2009-01-29 Thread Steven D'Aprano
e >> following would have given me the same result: x, y = y, x >> >> But could the swapping be done using less extra memory than this? What >> is the minimum amount of extra memory required to exchange two 32-bit >> quantities? What would be the pseudocode that achieve

Re: Swapping values of two variables

2009-01-29 Thread Steven D'Aprano
On Thu, 29 Jan 2009 16:29:11 -0800, Eric Kang wrote: > In python, I set: > > x=1 > y=3 > > z = x > x = y > y = z > > > This gave me 3 1, which are the values of x and y swapped. The following > would have given me the same result: x, y = y, x Yes. &g

Re: Swapping values of two variables

2009-01-29 Thread tony . clarke5
On Jan 30, 12:29 am, Eric Kang wrote: > In python, I set: > > x=1 > y=3 > > z = x > x = y > y = z > > This gave me 3 1, which are the values of x and y swapped. > The following would have given me the same result: > x, y = y, x > > But could the swapping

Re: Swapping values of two variables

2009-01-29 Thread MRAB
Eric Kang wrote: In python, I set: x=1 y=3 z = x x = y y = z This gave me 3 1, which are the values of x and y swapped. The following would have given me the same result: x, y = y, x But could the swapping be done using less extra memory than this? What is the minimum amount of extra memory

Swapping values of two variables

2009-01-29 Thread Eric Kang
In python, I set: x=1 y=3 z = x x = y y = z This gave me 3 1, which are the values of x and y swapped. The following would have given me the same result: x, y = y, x But could the swapping be done using less extra memory than this? What is the minimum amount of extra memory required to

Re: swapping

2007-08-20 Thread Gabriel Genellina
En Sat, 18 Aug 2007 02:58:23 -0300, Beema shafreen <[EMAIL PROTECTED]> escribi�: > result: > klp5bub1 > > apn1apn2 > > but i have do the same for the revere ,to check the result like this for > eg: > apn2apn1 > what is the concept to do this I don't understand exactly what you want

swapping

2007-08-18 Thread Beema shafreen
hi everbody, i have a file with data: fhl1fkh2 dfp1chk1 mal3alp14 mal3moe1 mal3spi1 mal3bub1 mal3bub3 mal3mph1 mal3mad3 hob1nak1 i have written code to check the redudant pairs my code: data = [] data1 = [] fh = open('sheet1','r') for line in fh: if

Re: swapping numeric items in a list

2006-08-23 Thread Jiang Nutao
>; Sent: Wednesday, August 23, 2006 12:19 PM Subject: Re: swapping numeric items in a list > At Wednesday 23/8/2006 15:32, Jiang Nutao wrote: > >>This is what I got in the debugger: >> >>(Pdb) aa=array('b', [126, 55, 71, 112]) >>(Pdb) aa >>array(&#x

Re: swapping numeric items in a list

2006-08-23 Thread Gabriel Genellina
At Wednesday 23/8/2006 15:32, Jiang Nutao wrote: This is what I got in the debugger: (Pdb) aa=array('b', [126, 55, 71, 112]) (Pdb) aa array('b', [126, 55, 71, 112]) (Pdb) aa.byteswap() (Pdb) aa array('b', [126, 55, 71, 112]) Oh, sorry, to swap by two bytes "H" was the right typecode. But your

Re: swapping numeric items in a list

2006-08-23 Thread Fredrik Lundh
Jiang Nutao wrote: > array.byteswap() won't work for me easily. I tried this before my 1st post. > I defined > > aa = array('H', [0x12, 0x34, 0x56, 0x78]) > > Then did byteswap aa.byteswap(). The result was > > array('H', [0x1200, 0x3400, 0x5600, 0x7800]) > > You can see it byteswappe

Re: swapping numeric items in a list

2006-08-23 Thread Jiang Nutao
]> To: "Jiang Nutao" <[EMAIL PROTECTED]> Cc: Sent: Wednesday, August 23, 2006 11:28 AM Subject: Re: swapping numeric items in a list > At Wednesday 23/8/2006 14:44, Jiang Nutao wrote: > >>array.byteswap() won't work for me easily. I tried this before my 1st >&g

Re: swapping numeric items in a list

2006-08-23 Thread Gabriel Genellina
At Wednesday 23/8/2006 14:44, Jiang Nutao wrote: array.byteswap() won't work for me easily. I tried this before my 1st post. I defined aa = array('H', [0x12, 0x34, 0x56, 0x78]) Then did byteswap aa.byteswap(). The result was array('H', [0x1200, 0x3400, 0x5600, 0x7800]) You can see it

Re: swapping numeric items in a list

2006-08-23 Thread Jiang Nutao
Thank you all guys for the help. Guess I'm gonna pick bearophile's way. It's fast, neat, and easy to read. array.byteswap() won't work for me easily. I tried this before my 1st post. I defined aa = array('H', [0x12, 0x34, 0x56, 0x78]) Then did byteswap aa.byteswap(). The result was ar

Re: swapping numeric items in a list

2006-08-23 Thread Boris Borcic
Jiang Nutao wrote: > Hi, > > I simplify my problem like below > > To convert list > aa = [0x12, 0x34, 0x56, 0x78] > into > [0x34, 0x12, 0x78, 0x56] > > How to do it fast? My real list is huge. Mark Rintsch's suggestion appears best if applicable, but just to cite yet other ways to do

Re: swapping numeric items in a list

2006-08-23 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Jiang Nutao wrote: > To convert list > aa = [0x12, 0x34, 0x56, 0x78] > into > [0x34, 0x12, 0x78, 0x56] > > How to do it fast? My real list is huge. Use the `array` module and the `array.byteswap()` method. Ciao, Marc 'BlackJack' Rintsch -- http://mail.py

Re: swapping numeric items in a list

2006-08-22 Thread bearophileHUGS
Jiang Nutao: > To convert list > aa = [0x12, 0x34, 0x56, 0x78] > into > [0x34, 0x12, 0x78, 0x56] > How to do it fast? My real list is huge. Note that: >>> a = range(6) >>> a [0, 1, 2, 3, 4, 5] >>> a[::2] [0, 2, 4] >>> a[1::2] [1, 3, 5] So you can do: >>> a[::2], a[1::2] = a[1::2], a[::2

Re: swapping numeric items in a list

2006-08-22 Thread Simon Forman
Jiang Nutao wrote: > Hi, > > I simplify my problem like below > > To convert list > aa = [0x12, 0x34, 0x56, 0x78] > into > [0x34, 0x12, 0x78, 0x56] > > How to do it fast? My real list is huge. > > Thanks a lot. > Jason Here's simple and probably fast enough way (but it won't work right on

Re: swapping numeric items in a list

2006-08-22 Thread faulkner
for i in xrange(0, len(your_list), 2): your_list[i], your_list[i + 1] = your_list[i + 1], your_list[i] Jiang Nutao wrote: > Hi, > > I simplify my problem like below > > To convert list > aa = [0x12, 0x34, 0x56, 0x78] > into > [0x34, 0x12, 0x78, 0x56] > > How to do it fast? My real li

swapping numeric items in a list

2006-08-22 Thread Jiang Nutao
Hi, I simplify my problem like below To convert list aa = [0x12, 0x34, 0x56, 0x78] into [0x34, 0x12, 0x78, 0x56] How to do it fast? My real list is huge. Thanks a lot. Jason -- http://mail.python.org/mailman/listinfo/python-list