this is simple...
I am a newbie... and the first to admit it... but this has me stuffed: I have two lists A and B that are both defined as range(1,27) I want to find the entries that are valid for A = BxB so here is my code: A = range(1,27) B = range(1,27) for b in B: if b*b in A: print b else: B.remove(b) I get, as expected 1,4,9,16,25 printed out being the only members of B where the condition is true, but when I print B I get: [1, 2, 3, 4, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25] 1 to 5 is correct, but why doesn't the remove method remove 7 and above? What am I doing wrong here? -- http://mail.python.org/mailman/listinfo/python-list
Re: this is simple...
On Jun 28, 2:48 pm, Mel <[EMAIL PROTECTED]> wrote: > ToshiBoy wrote: > > I have two lists A and B that are both defined as range(1,27) I want > > to find the entries that are valid for A = BxB > [ ... ] > > I get, as expected 1,4,9,16,25 printed out being the only members of B > > where the condition is true, but when I print B I get: > > > [1, 2, 3, 4, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25] > > > 1 to 5 is correct, but why doesn't the remove method remove 7 and > > above? What am I doing wrong here? > > Try this: > > A = range(1,27) > B = range(1,27) > C = [] > > for b in B: > print "Trying", b > if b*b in A: > print b > C.append (b) > else: > print "Removing", b > B.remove(b) > print 'B', B > print 'C', C > > The essential problem is that your `B.remove`s are pulling the rug out from > under your `for b in B:`. There are ways to mess with B while you iterate. > Running though B backwards will do: `for b in B[::-1]:`, or iterating over > a copy of B: `for b in B[:]:` or `for b in list(B):`. Leaving B alone and > building up the desired items in C is probably simplest. > > Mel. Thank you, of course! :-) Didn't even think of that... that I was modifying my iterators... Thank you -- http://mail.python.org/mailman/listinfo/python-list
Project Question
I'm a newbie to Python... well a newbie to programming, really. I know the basics and try to learn by setting myself simple tasks and goals just to find out if I can work out a way to code the solutions. Works for me. However, now I've set my eyes on a more ambitious project: We sell office machines, and most of them need to be connected to a network these days. I've got a routine setup for each model which enters the most common information, eg. NetBIOS names, mailservers, etc.The information is input through a webinterface as you have probably seen on many other printers. Currently, I'm using iMacro, an add-on to Firefox, which runs a macro and enters all the info. It's great, but I would like to try and write a program for this in Python. It needs to collect some user input at the beginning, and then open the default web browser (or preferably runs its own interface) and enter the information by identifying the fields and inputting the text, and "saving" the info by "clicking" buttons. Is there a web browser interface module in Python that would have methods to do this kind of stuff? -- http://mail.python.org/mailman/listinfo/python-list
Re: Project Question
Great, I think that's exactly what I'm after. Thank you! Simon Brunning wrote: 2008/8/3 ToshiBoy <[EMAIL PROTECTED]>: Currently, I'm using iMacro, an add-on to Firefox, which runs a macro and enters all the info. It's great, but I would like to try and write a program for this in Python. It needs to collect some user input at the beginning, and then open the default web browser (or preferably runs its own interface) and enter the information by identifying the fields and inputting the text, and "saving" the info by "clicking" buttons. Is there a web browser interface module in Python that would have methods to do this kind of stuff? Take a look at Mechanize: <http://wwwsearch.sourceforge.net/mechanize/>. -- http://mail.python.org/mailman/listinfo/python-list
list question... unique values in all possible unique spots
I'm wondering how to do this the most elegant way: I found this quiz in some magazine. I've already solved it on paper, but want to write a python program to solve it. It comes down to being able to represent range(1,27) through a number of formulas. How do I write a loop that will loop through this list, so that: 1. every number only occurs once, and 2. I get every possibility of order within the list? I guess it'd be somewhat similar to Sudoku, where you have the numbers from 1-9 in any possible order. Here it's 1-26. -- http://mail.python.org/mailman/listinfo/python-list
Re: list question... unique values in all possible unique spots
Thank you for all your responses. I've tried the permutations road (thank you to all those of you who have suggested it) and it takes %*& %^ long :-) As expected. I've solved it a different way, which runs through the 26 spots by just adding one at a time if available. Still takes a long time, but not as long as the permutation. That said,the permutation works great for other projects. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Installation and Running on Windows Vista
I don't use it often in Vista, but I haven't had any issues. Matter-of- fact, some things seem nicer in Vista... for instance it resets IDLE whenever I rerun a module. Mchizi_Crazy wrote: > Please help with issue... I heard of compatimbiltity issues and would > like clarification. -- http://mail.python.org/mailman/listinfo/python-list