Hi all,
I've been trying to write a programme that solves sudoku problems for a
while now. I'm getting close, but would like to ask a few questions about
the most pythonic way of doing some things.
I've decided to create nested lists (row order, column order and square
order) which correspond with
Thanks David, But the loop was suppose to produce the count of even divisors an
integer has.
Like, 6 has 2 "even" divisors, which is 2 and 6, itself.
8 = 3 even divisors, which is 2, 4 ,and 8
10 = 2 even divisors, which is 2, and 10
12 = 4 even divisors, which is 2, 4, 6, and 12
sorry, I just don
On 09/28/10 13:57, Bill Allen wrote:
> I can now see that quite a bit of the code I write dealing with lists
> can be done with list
> comprehensions. My question is this, is the list comprehension styled
> code generally
> more efficient at runtime? If so, why?
Yes, because the looping in list
On Tue, Sep 28, 2010 at 12:15 AM, masawudu bature wrote:
> I'm having a hard time finding the count of divisors that are even. Help
> anybody?
>
> Here's my code.
>
> The output is suppose to count the number of even divisors the range has.
>
> def evenCount(b) :
> for n in range(x, y+1) :
>
I'm having a hard time finding the count of divisors that are even. Help
anybody?
Here's my code.
The output is suppose to count the number of even divisors the range has.
def evenCount(b) :
for n in range(x, y+1) :
count = 0
if n % 2 == 0 :
count += n/3
I have seen list comprehensions used, but have not quite got the hang of it
yet.
So, I was writing a bit of code to do some work with file directories and
decided
to give it a try as follows:
list_c = os.listdir("c:")
#first code written in the way I usually would.
dirs = []
for x in list_c:
On 2:59 PM, Steven D'Aprano wrote:
On Tue, 28 Sep 2010 08:55:36 am Carter Danforth wrote:
class Date:
c = random.randint(16,30)
y = random.randint(0,99)
month = random.randint(1,12)
Here's your problem: you are creating a class where all the attributes
(called "members" in som
On 9/27/10, Steven D'Aprano wrote:
> On Tue, 28 Sep 2010 06:00:41 am Alex Hall wrote:
>> > [ [0]*3 ]*4 behaves the same way. There's no problem in the inner
>> > list, but the outer list doesn't make four copies of [0,0,0], it
>> > has *one* list repeated four times. Modify one, modify them all.
>
You might try fixing up the following. I did not match the scale to what you
are looking for. But the trick is to take advantage of the time module's association
of numbers with dates:
import time
import random
""" Sample output
Wed Apr 29 14:35:58 1992
Thu Jun 24 12:04:15 1971
Fri Oct 7
On Tue, 28 Sep 2010 08:07:30 am Modulok wrote:
> On 9/27/10, Steven D'Aprano wrote:
> > On Tue, 28 Sep 2010 04:03:17 am Modulok wrote:
> >> List,
> >>
> >> When using the unittest module, tests are run in alphanumeric
> >> order. What's the suggested way of specifying a test order?
> >
> > There i
On Tue, 28 Sep 2010 06:00:41 am Alex Hall wrote:
> > [ [0]*3 ]*4 behaves the same way. There's no problem in the inner
> > list, but the outer list doesn't make four copies of [0,0,0], it
> > has *one* list repeated four times. Modify one, modify them all.
>
> That makes sense. Basically, the * ope
On Tue, 28 Sep 2010 08:55:36 am Carter Danforth wrote:
> class Date:
> c = random.randint(16,30)
> y = random.randint(0,99)
> month = random.randint(1,12)
Here's your problem: you are creating a class where all the attributes
(called "members" in some other languages) belong to the c
64-bit Vista
Python 2.6 for IPython 0.10
I also have Python 2.7 and 3.1
I'd like to use the version of IDLE that comes with Python 2.6.
However, if I have the line
ipy_editors.idle()
in my ipy_user_conf.py,
And enter edit,
What opens is the IDLE for Python 3.1.
So, in imitation of this line
On 9/27/10, Sander Sweers wrote:
> On 27 September 2010 23:15, Sander Sweers wrote:
>>> objects: copying the memory location, not making a deep copy and
>>> getting a duplicate object.
>>
>> It does not copy the object it makes multiple _references_ to the *same*
>> object.
>
> Oops, You already
Hi, I'm writing a program that's testing speed calculation of calendar dates
from any date spanning 1600-3000. I want it to generate a random date and
then prompt the user to indicate the correct day of the week using Zeller's
formula.
Included below is just some of the code to show what I'm havin
On 27-Sep-10 15:07, Modulok wrote:
In an ideal world, I agree. This is possible for pure functional
programming where state is avoided. However, when dealing with object
oriented, imperative programming, state changes cannot be avoided.
Generally, a unit test should test a single aspect of a si
On 9/27/10, Steven D'Aprano wrote:
> On Tue, 28 Sep 2010 04:03:17 am Modulok wrote:
>> List,
>>
>> When using the unittest module, tests are run in alphanumeric order.
>> What's the suggested way of specifying a test order?
>
> There isn't one. It shouldn't matter what order the tests run, no test
On 9/27/2010 1:22 PM Norman Khine said...
what is the correct way to ensure that {'industry': 'travel', 'name':
'other','value': MSG(u"Other")} is always added to the end of this
list after all the items have been sorted?
here is the code which returns this list:
options.sort(key=itemgette
On 27 September 2010 23:15, Sander Sweers wrote:
>> objects: copying the memory location, not making a deep copy and
>> getting a duplicate object.
>
> It does not copy the object it makes multiple _references_ to the *same*
> object.
Oops, You already got the idea and I should have read better.
On 27 September 2010 22:00, Alex Hall wrote:
> That makes sense. Basically, the * operator in this case acts as a
> copying command. For simple data types this is fine, but throw in a
> complex type, in this case a list (though I expect that any object
> would do this) and you are just doing what
hello, i have a list which is generated from a csv file:
options = [
{'industry': 'travel', 'name': 'owner-director','value':
MSG(u"Owner/Director")},
{'industry': 'travel', 'name': 'manager','value': MSG(u"Manager")},
{'industry': 'travel', 'name': 'assistant-manager','val
On 9/27/10, Steven D'Aprano wrote:
> On Tue, 28 Sep 2010 03:54:55 am Alex Hall wrote:
>> Hi again everyone,
>> I have a 2d array (I guess it is technically a list) which I want to
>> fill with zeros. Later I will change some values, but any I do not
>> change have to be zeros. I have two complex f
Am 27.09.2010 20:29, schrieb Steven D'Aprano:
On Tue, 28 Sep 2010 03:54:55 am Alex Hall wrote:
Hi again everyone,
I have a 2d array (I guess it is technically a list) which I want to
fill with zeros. Later I will change some values, but any I do not
change have to be zeros. I have two complex fo
>> List,
>>
>> When using the unittest module, tests are run in alphanumeric order.
>> What's the suggested way of specifying a test order?
>
> There isn't one. It shouldn't matter what order the tests run, no test
> should *rely* on another test.
>
> (Although of course, if one test fails, a
On 9/27/2010 10:54 AM Alex Hall said...
What is wrong with the following line?
self.am=[[(a,b)
for a in range(len(self.lines)) a=0]
for b in range(len(self.lines)) b=0]
The a=0 and b=0 -- what do you think they're doing?
Emile
___
Tutor maill
I'm guessing you are also using numpy and that you want arrays (or matrices) for
the sake of either (a) matrix and array functions or (b) much greater processing
speed.
Add
from numpy import *
Then hat you can do is go back and forth: Build what you intend to be an array,
but build it as
On Tue, 28 Sep 2010 04:03:17 am Modulok wrote:
> List,
>
> When using the unittest module, tests are run in alphanumeric order.
> What's the suggested way of specifying a test order?
There isn't one. It shouldn't matter what order the tests run, no test
should *rely* on another test.
(Although
On Tue, 28 Sep 2010 03:54:55 am Alex Hall wrote:
> Hi again everyone,
> I have a 2d array (I guess it is technically a list) which I want to
> fill with zeros. Later I will change some values, but any I do not
> change have to be zeros. I have two complex for loops, but I tried to
> scale things do
On Mon, Sep 27, 2010 at 1:54 PM, Alex Hall wrote:
> Hi again everyone,
> I have a 2d array (I guess it is technically a list) which I want to
> fill with zeros. Later I will change some values, but any I do not
> change have to be zeros. I have two complex for loops, but I tried to
> scale things
On Mon, Sep 27, 2010 at 1:52 PM, Steven D'Aprano wrote:
> On Tue, 28 Sep 2010 02:12:55 am Joel Goldstick wrote:
>
>> a=[]
>> i=0
>> for l in open("file.txt", "r"):
>> a[i]=l
>> i+=1
>
> Did you try it before posting?
>
That is a copy of the OP post. and it shows what didn't work
I deleted in
List,
When using the unittest module, tests are run in alphanumeric order.
What's the suggested way of specifying a test order? Any code examples
would be great!
Thanks
-Modulok-
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscript
hello,
i have the following error when i call this function:
20 def outOfBounds():
---> 21 if abs(turtle.position()[0]) >
turtle.window_height()/2 or abs(turtle.position()[1]) >
turtle.window_width()/2:
22 return "true"
23 else:
TypeError: 'function' ob
On Tue, 28 Sep 2010 01:32:32 am Alex Hall wrote:
> Hi all,
> One thing I have never much liked about Python is its need for
> specifically sized arrays and lack of a dynamic, array-like data
> structure.
Python lists are dynamically sized. If you compare Python to languages
with fixed-size arrays
Hi again everyone,
I have a 2d array (I guess it is technically a list) which I want to
fill with zeros. Later I will change some values, but any I do not
change have to be zeros. I have two complex for loops, but I tried to
scale things down to a couple list comprehensions and I broke things.
What
On Tue, 28 Sep 2010 02:12:55 am Joel Goldstick wrote:
> a=[]
> i=0
> for l in open("file.txt", "r"):
> a[i]=l
> i+=1
Did you try it before posting?
--
Steven D'Aprano
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription o
On Tue, 28 Sep 2010 01:45:56 am Brian Jones wrote:
> A python list and a python array are one and the same to my
> knowledge.
Close, but not quite.
Python has an array type. It is almost identical to lists, except the
type of data it will hold is constrained to a specific type:
>>> import arra
On Tue, 28 Sep 2010 01:09:54 am Tim Miller wrote:
> def complex_password(password):
> """Checks password for sufficient complexity."""
> if len(password) < 12:
> return False
> if len([c for c in password if c in punctuation]) == 0:
> return False
> if len([c
On 28/09/10 01:50, Brian Jones wrote:
On Mon, Sep 27, 2010 at 11:43 AM, Brian Jones mailto:bkjo...@gmail.com>> wrote:
How about this:
d = [digits, punctuation, ascii_uppercase, ascii_lowercase]
s = 'asdf1234A'
for c in d:
if not [x for x in s if x in c]:
print x, ' not in ', c
Ju
On 28/09/10 01:46, Jerry Hill wrote:
The way you've written it obviously works fine. That being said, I'd
probably do something like this:
from string import ascii_lowercase, ascii_uppercase, digits, punctuation
def complex_password(password):
'''Checks to make sure a password is complex'
set does seem to have what you want: isdisjoint() could do the trick.
Eg:
if set(punctuation).isdisjoint(password) or
set(digits).isdisjoint(password) or set(ascii_uppercase).isdisjoint(password)
or set(ascii_lowercase).isdisjoint(password):
return False
return True
You co
> Hi all,
>> >> One thing I have never much liked about Python is its need for
>> >> specifically sized arrays and lack of a dynamic, array-like data
>> >> structure. For example, the following fails with a "list assignment
>> >> index out of range" error:
a=[]
i=0
for l in open("file.txt", "r"):
On 2:59 PM, Alex Hall wrote:
On 9/27/10, Brian Jones wrote:
On Mon, Sep 27, 2010 at 11:32 AM, Alex Hall wrote:
Hi all,
One thing I have never much liked about Python is its need for
specifically sized arrays and lack of a dynamic, array-like data
structure. For example, the following fails
On 9/27/10, Brian Jones wrote:
> On Mon, Sep 27, 2010 at 11:39 AM, Alex Hall wrote:
>
>> On 9/27/10, Brian Jones wrote:
>> > On Mon, Sep 27, 2010 at 11:32 AM, Alex Hall wrote:
>> >
>> >> Hi all,
>> >> One thing I have never much liked about Python is its need for
>> >> specifically sized arrays
> I've got a small function that I'm using to check whether a password is of a
> certain length and contains mixed case, numbers and punctuation.
>
> Originally I was using multiple "if re.search" for the patterns but it looked
> terrible so I've read up on list comprehensions and it's slightly
On Mon, Sep 27, 2010 at 11:43 AM, Brian Jones wrote:
>
>
> On Mon, Sep 27, 2010 at 11:09 AM, Tim Miller wrote:
>
>> I've got a small function that I'm using to check whether a password is of
>> a certain length and contains mixed case, numbers and punctuation.
>>
>> Originally I was using multip
On Mon, Sep 27, 2010 at 11:39 AM, Alex Hall wrote:
> On 9/27/10, Brian Jones wrote:
> > On Mon, Sep 27, 2010 at 11:32 AM, Alex Hall wrote:
> >
> >> Hi all,
> >> One thing I have never much liked about Python is its need for
> >> specifically sized arrays and lack of a dynamic, array-like data
>
On Mon, Sep 27, 2010 at 11:09 AM, Tim Miller wrote:
> I've got a small function that I'm using to check whether a password is of a
> certain length and contains mixed case, numbers and punctuation.
>
> Originally I was using multiple "if re.search" for the patterns but it
> looked terrible so I've
On Mon, Sep 27, 2010 at 9:32 AM, Alex Hall wrote:
> Hi all,
> One thing I have never much liked about Python is its need for
> specifically sized arrays and lack of a dynamic, array-like data
> structure. For example, the following fails with a "list assignment
> index out of range" error:
>
> a=
On Mon, Sep 27, 2010 at 11:09 AM, Tim Miller wrote:
> I've got a small function that I'm using to check whether a password is of
> a certain length and contains mixed case, numbers and punctuation.
>
> Originally I was using multiple "if re.search" for the patterns but it
> looked terrible so I'v
On 9/27/10, Brian Jones wrote:
> On Mon, Sep 27, 2010 at 11:32 AM, Alex Hall wrote:
>
>> Hi all,
>> One thing I have never much liked about Python is its need for
>> specifically sized arrays and lack of a dynamic, array-like data
>> structure. For example, the following fails with a "list assign
> One thing I have never much liked about Python is its need for
> specifically sized arrays and lack of a dynamic, array-like data
> structure. For example, the following fails with a "list assignment
> index out of range" error:
>
> a=[]
> i=0
> for l in open("file.txt", "r"):
> a[i]=l
> i+=1
On Mon, Sep 27, 2010 at 11:32 AM, Alex Hall wrote:
> Hi all,
> One thing I have never much liked about Python is its need for
> specifically sized arrays and lack of a dynamic, array-like data
> structure. For example, the following fails with a "list assignment
> index out of range" error:
>
> a
Hi all,
One thing I have never much liked about Python is its need for
specifically sized arrays and lack of a dynamic, array-like data
structure. For example, the following fails with a "list assignment
index out of range" error:
a=[]
i=0
for l in open("file.txt", "r"):
a[i]=l
i+=1
Is there
I've got a small function that I'm using to check whether a password is
of a certain length and contains mixed case, numbers and punctuation.
Originally I was using multiple "if re.search" for the patterns but it
looked terrible so I've read up on list comprehensions and it's slightly
improved
Thanks Guys! Works perfect
cheers
On Mon, Sep 27, 2010 at 1:01 PM, Wayne Werner wrote:
> In addition it only works for new style classes.
>
> -wayne
>
> On 9/27/10, Lie Ryan wrote:
> > On 09/27/10 09:45, Jojo Mwebaze wrote:
> >> Hey Tutor,
> >>
> >> Seems a small issue but this has been p
Thanks Guys! Works perfect
cheers
On Mon, Sep 27, 2010 at 1:01 PM, Wayne Werner wrote:
> In addition it only works for new style classes.
>
> -wayne
>
> On 9/27/10, Lie Ryan wrote:
> > On 09/27/10 09:45, Jojo Mwebaze wrote:
> >> Hey Tutor,
> >>
> >> Seems a small issue but this has been p
I looked up the word zoeken -- it means find in English.
I looked up the chapter and exercise in the online text "How to think
like a computer scientist"
Its a good tutorial.
I think the OP seems to get confused on basic concepts.
Here is my stab at the exercise:
#!/usr/bin/env python
"""This
On 2:59 PM, Roelof Wobben wrote:
Hello,
Fine that you are in a arque
But can we come back to my problem.
How can I take care that test2 can be initialized.
Roelof
You had this code, and got the following error:
class zoeken() :
pass
def __len__(self):
return 0
def __st
In addition it only works for new style classes.
-wayne
On 9/27/10, Lie Ryan wrote:
> On 09/27/10 09:45, Jojo Mwebaze wrote:
>> Hey Tutor,
>>
>> Seems a small issue but this has been playing for a while now, what am i
>> doing wrong here?
>>
>
> super() without argument only works for Python 3.
Hello,
Fine that you are in a arque
But can we come back to my problem.
How can I take care that test2 can be initialized.
Roelof
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscri
On 09/27/10 09:45, Jojo Mwebaze wrote:
> Hey Tutor,
>
> Seems a small issue but this has been playing for a while now, what am i
> doing wrong here?
>
super() without argument only works for Python 3. In Python 2.x, you
have to pass to super your class name and your class instance, i.e.:
Class
61 matches
Mail list logo