[Tutor] Removing values from a dictionary if they are present in a list

2011-04-01 Thread ranjan das
I have the following information A={'g2': [4,5,3], 'g1': [1, 3]} B=[2,3,5] Now I want to remeove the elements in B if they are present (as values) in dictionary A. My expected solution is A= {'g2': [4], 'g1': [1] } I wrote the following piece of code which gives me thhe right code, but I am s

Re: [Tutor] Removing values from a dictionary if they are present in alist

2011-04-01 Thread Alan Gauld
"ranjan das" wrote A={'g2': [4,5,3], 'g1': [1, 3]} B=[2,3,5] Now I want to remeove the elements in B if they are present (as values) in dictionary A. My first thought was to start with the dictionary, something like for key in A: A[key] = [val for val in A[key] if val not in B] Dunn

Re: [Tutor] Removing values from a dictionary if they are present in a list

2011-04-01 Thread Peter Otten
ranjan das wrote: > I have the following information > > A={'g2': [4,5,3], 'g1': [1, 3]} > > B=[2,3,5] > > Now I want to remeove the elements in B if they are present (as values) in > dictionary A. > > My expected solution is > > A= {'g2': [4], 'g1': [1] } > > I wrote the following piece of

Re: [Tutor] Importing sub modules

2011-04-01 Thread Alan Gauld
"bob gailer" wrote On 3/31/2011 1:07 PM, Prasad, Ramit wrote: This communication is for informational purposes only. It is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. All market prices, .

Re: [Tutor] Removing values from a dictionary if they are present in a list

2011-04-01 Thread Andre Engels
On Fri, Apr 1, 2011 at 9:52 AM, ranjan das wrote: > I have the following information > > A={'g2': [4,5,3], 'g1': [1, 3]} > > B=[2,3,5] > > Now I want to remeove the elements in B if they are present (as values) in > dictionary A. > > My expected solution is > > A= {'g2': [4], 'g1': [1] } > > I wro

Re: [Tutor] Removing values from a dictionary if they are present in a list

2011-04-01 Thread Steven D'Aprano
ranjan das wrote: I have the following information A={'g2': [4,5,3], 'g1': [1, 3]} B=[2,3,5] Now I want to remeove the elements in B if they are present (as values) in dictionary A. My expected solution is A= {'g2': [4], 'g1': [1] } Do you care about the order of the elements in A's value

Re: [Tutor] Removing values from a dictionary if they are present in a list

2011-04-01 Thread Peter Otten
Steven D'Aprano wrote: > b = set(B) > for key, values in A.items(): > A[key] = list( set(values).difference(b) ) > > > For Python 3, you will need to change the call A.items() to > list(A.items()), but otherwise they should be the same. The documentation doesn't say so explicitly, see http

Re: [Tutor] Importing sub modules

2011-04-01 Thread Prasad, Ramit
>However the sub-modules co.py and order.py are *not* imported by the >main module. They are only loaded on demand, when you say "import >stats.co" or "from stats.order import median" or similar. >So it depends on the module. That is exactly what I wondering and an excellent example to illustra

[Tutor] PyVISA GPIB

2011-04-01 Thread markrivet
I would like to control electronic instruments with PyVISA. I have downloaded PyVISA and unpacked the files into the Python27/lib/site-packages dir and in the IDLE GUI I run "import visa' for a quick check and I get this error: import visa Traceback (most recent call last): File "", line 1,

Re: [Tutor] argparse csv + choices

2011-04-01 Thread Karim
On 03/30/2011 06:05 PM, Robert Kern wrote: On 3/30/11 10:32 AM, Neal Becker wrote: I'm trying to combine 'choices' with a comma-seperated list of options, so I could do e.g., --cheat=a,b parser.add_argument ('--cheat', choices=('a','b','c'), type=lambda x: x.split(','), default=[]) te

Re: [Tutor] PyVISA GPIB

2011-04-01 Thread Donald Bedsole
Hi Mark, On Fri, Apr 1, 2011 at 11:42 AM, wrote: >  I would like to control electronic instruments with PyVISA. I have > downloaded PyVISA and unpacked the files into the Python27/lib/site-packages > dir and in the IDLE > GUI I run "import visa' for a quick check and I get this error: > > impo

[Tutor] Meta language and code generation

2011-04-01 Thread Karim
Hello All, I would to ask you if somebody has experience or can give direction in a new project I have. I have a meta language description (in xml) from which I should generate code on different languages. In my case, lisp and tcl. Any idea in term of design, examples, links will be appreci

Re: [Tutor] PyVISA GPIB

2011-04-01 Thread Donald Bedsole
Sorry, On Fri, Apr 1, 2011 at 1:00 PM, Donald Bedsole wrote: > Hi Mark, > > On Fri, Apr 1, 2011 at 11:42 AM,   wrote: >>  I would like to control electronic instruments with PyVISA. I have >> downloaded PyVISA and unpacked the files into the Python27/lib/site-packages >> dir and in the IDLE >>

Re: [Tutor] Run application from MS-DOS with sys.argv

2011-04-01 Thread Susana Iraiis Delgado Rodriguez
Hello! I'm going to answer to the question I posted in this list. After a search trouhg web and analize the code, I just had to add a try/except statement. Now I get what I need. Here is the information: directorio = sys.argv[1] extension = sys.argv[2] csv_salida = sys.argv[3] #Here I add the lin

Re: [Tutor] PyVISA GPIB

2011-04-01 Thread Blockheads Oi Oi
On 01/04/2011 18:00, Donald Bedsole wrote: Hi Mark, On Fri, Apr 1, 2011 at 11:42 AM, wrote: I would like to control electronic instruments with PyVISA. I have downloaded PyVISA and unpacked the files into the Python27/lib/site-packages dir and in the IDLE GUI I run "import visa' for a quic

[Tutor] counting a list of elements

2011-04-01 Thread Karim
Hello, I would like to get advice on the best practice to count elements in a list (built from scractch). The number of elements is in the range 1e3 and 1e6. 1) I could create a generator and set a counter (i +=1) in the loop. 2) or simply len(mylist). I don't need the content of the list,

Re: [Tutor] Meta language and code generation

2011-04-01 Thread Tino Dai
On Fri, Apr 1, 2011 at 1:09 PM, Karim wrote: > > Hello All, > > I would to ask you if somebody has experience or can give direction in a > new project I have. > I have a meta language description (in xml) from which I should generate > code on different > languages. In my case, lisp and tcl. > >

Re: [Tutor] PyVISA GPIB

2011-04-01 Thread markrivet
"Donald Bedsole" said: > Sorry, > > On Fri, Apr 1, 2011 at 1:00 PM, Donald Bedsole wrote: >> Hi Mark, >> >> On Fri, Apr 1, 2011 at 11:42 AM,   wrote: >>>  I would like to control electronic instruments with PyVISA. I have >>> downloaded PyVISA and unpacked the files into the >>> Python27/lib

Re: [Tutor] PyVISA GPIB

2011-04-01 Thread markrivet
"Donald Bedsole" said: > Hi Mark, > > On Fri, Apr 1, 2011 at 11:42 AM, wrote: >>  I would like to control electronic instruments with PyVISA. I have >> downloaded PyVISA and unpacked the files into the Python27/lib/site-packages >> dir >> and in the IDLE >> GUI I run "import visa' for a qui

Re: [Tutor] PyVISA GPIB

2011-04-01 Thread markrivet
"Donald Bedsole" said: > Sorry, > > On Fri, Apr 1, 2011 at 1:00 PM, Donald Bedsole wrote: >> Hi Mark, >> >> On Fri, Apr 1, 2011 at 11:42 AM,   wrote: >>>  I would like to control electronic instruments with PyVISA. I have >>> downloaded PyVISA and unpacked the files into the >>> Python27/lib

Re: [Tutor] counting a list of elements

2011-04-01 Thread Emile van Sebille
On 4/1/2011 10:16 AM Karim said... I would like to get advice on the best practice to count elements Well, I suspect you're more interested in knowing the total count of how many as opposed to counting how many. To get the total count of how many use len(mylist). Emile __

Re: [Tutor] counting a list of elements

2011-04-01 Thread Knacktus
Am 01.04.2011 19:16, schrieb Karim: Hello, I would like to get advice on the best practice to count elements in a list (built from scractch). It's not clear to me what your starting point is. If you don't have a list and don't need a list, but have a large number of objects you create in y

Re: [Tutor] counting a list of elements

2011-04-01 Thread James Reynolds
The nice thing about Python is you don't have to build things from scratch, and I imagine most people would discourage on account of it being a waste of time, other then education value. But the "best practice" in my humble opinion would be to use the built in len function. If what you are after i

Re: [Tutor] Meta language and code generation

2011-04-01 Thread Knacktus
Am 01.04.2011 19:09, schrieb Karim: Hello All, I would to ask you if somebody has experience or can give direction in a new project I have. I have a meta language description (in xml) from which I should generate code on different languages. In my case, lisp and tcl. You need to provide more

Re: [Tutor] counting a list of elements

2011-04-01 Thread Knacktus
Am 01.04.2011 19:16, schrieb Karim: Hello, I would like to get advice on the best practice to count elements in a list (built from scractch). The number of elements is in the range 1e3 and 1e6. 1) I could create a generator and set a counter (i +=1) in the loop. 2) or simply len(mylist). I

Re: [Tutor] Meta language and code generation

2011-04-01 Thread Karim
On 04/01/2011 08:29 PM, Knacktus wrote: Am 01.04.2011 19:09, schrieb Karim: Hello All, I would to ask you if somebody has experience or can give direction in a new project I have. I have a meta language description (in xml) from which I should generate code on different languages. In my case,

Re: [Tutor] PyVISA

2011-04-01 Thread Mark R Rivet
Well I tried the setup file and here is what I get: C:\Users\Rivetmr\PyVisa_1.3\PyVISA-1.3>Python setup.py install Traceback (most recent call last): File "setup.py", line 60, in home_dir = os.environ['HOME'] File "C:\Python27\Lib\os.py", line 423, in __getitem__ return self.d

Re: [Tutor] Run application from MS-DOS with sys.argv

2011-04-01 Thread Blockheads Oi Oi
On 01/04/2011 18:15, Susana Iraiis Delgado Rodriguez wrote: Hello! I'm going to answer to the question I posted in this list. After a search trouhg web and analize the code, I just had to add a try/except statement. Now I get what I need. Here is the information: directorio = sys.argv[1] extens

Re: [Tutor] PyVISA

2011-04-01 Thread Alan Gauld
"Mark R Rivet" wrote Well I tried the setup file and here is what I get: C:\Users\Rivetmr\PyVisa_1.3\PyVISA-1.3>Python setup.py install Traceback (most recent call last): File "setup.py", line 60, in home_dir = os.environ['HOME'] Windows doesn't by default define a HOME environment vari

Re: [Tutor] PyVISA

2011-04-01 Thread Blockheads Oi Oi
On 01/04/2011 20:10, Alan Gauld wrote: "Mark R Rivet" wrote Well I tried the setup file and here is what I get: C:\Users\Rivetmr\PyVisa_1.3\PyVISA-1.3>Python setup.py install Traceback (most recent call last): File "setup.py", line 60, in home_dir = os.environ['HOME'] Windows doesn't by de

Re: [Tutor] counting a list of elements

2011-04-01 Thread Karim
On 04/01/2011 08:41 PM, Knacktus wrote: Am 01.04.2011 19:16, schrieb Karim: Hello, I would like to get advice on the best practice to count elements in a list (built from scractch). The number of elements is in the range 1e3 and 1e6. 1) I could create a generator and set a counter (i +=1) in

Re: [Tutor] PyVISA

2011-04-01 Thread Sotiris Tsartsaris
2011/4/1 Alan Gauld > > "Mark R Rivet" wrote > > > Well I tried the setup file and here is what I get: >> C:\Users\Rivetmr\PyVisa_1.3\PyVISA-1.3>Python setup.py install >> Traceback (most recent call last): >> File "setup.py", line 60, in >> home_dir = os.environ['HOME'] >> > > Windows does

Re: [Tutor] Meta language and code generation

2011-04-01 Thread Knacktus
Am 01.04.2011 20:56, schrieb Karim: On 04/01/2011 08:29 PM, Knacktus wrote: Am 01.04.2011 19:09, schrieb Karim: Hello All, I would to ask you if somebody has experience or can give direction in a new project I have. I have a meta language description (in xml) from which I should generate code

Re: [Tutor] counting a list of elements

2011-04-01 Thread Knacktus
Am 01.04.2011 21:31, schrieb Karim: On 04/01/2011 08:41 PM, Knacktus wrote: Am 01.04.2011 19:16, schrieb Karim: Hello, I would like to get advice on the best practice to count elements in a list (built from scractch). The number of elements is in the range 1e3 and 1e6. 1) I could create a g

[Tutor] Finding prime numbers script runs much faster when run via bash shell than idle

2011-04-01 Thread Jaime Gago
Hello there, Totally new to python with some *nix scripting knowledge. I wrote a simple piece of code as an exercise to an online -free- class that finds prime numbers. When I run it via IDLE it's taking way more time than if I run it via a (bash) shell (on Os X 10.6) while doing $>python -d myp

Re: [Tutor] Meta language and code generation

2011-04-01 Thread Karim
On 04/02/2011 06:38 AM, Knacktus wrote: Am 01.04.2011 20:56, schrieb Karim: On 04/01/2011 08:29 PM, Knacktus wrote: Am 01.04.2011 19:09, schrieb Karim: Hello All, I would to ask you if somebody has experience or can give direction in a new project I have. I have a meta language description

Re: [Tutor] counting a list of elements

2011-04-01 Thread Karim
On 04/02/2011 07:00 AM, Knacktus wrote: Am 01.04.2011 21:31, schrieb Karim: On 04/01/2011 08:41 PM, Knacktus wrote: Am 01.04.2011 19:16, schrieb Karim: Hello, I would like to get advice on the best practice to count elements in a list (built from scractch). The number of elements is in the

Re: [Tutor] Finding prime numbers script runs much faster when run via bash shell than idle

2011-04-01 Thread Karim
On 04/02/2011 07:10 AM, Jaime Gago wrote: Hello there, Totally new to python with some *nix scripting knowledge. I wrote a simple piece of code as an exercise to an online -free- class that finds prime numbers. When I run it via IDLE it's taking way more time than if I run it via a (bash) shel

Re: [Tutor] Finding prime numbers script runs much faster when run via bash shell than idle

2011-04-01 Thread Karim
On 04/02/2011 07:10 AM, Jaime Gago wrote: Hello there, Totally new to python with some *nix scripting knowledge. I wrote a simple piece of code as an exercise to an online -free- class that finds prime numbers. When I run it via IDLE it's taking way more time than if I run it via a (bash) shel