I've noticed that after 20 or 30 compile/link/execute runs, IDLE crashes. This seems to happen pretty consistently. At the time, I'm not doing anything that might cause it to crash. Does this happen to anyone else? What causes it? Is it just a bug? I have IDLE version 1.1.1 which came with Python 2.4. Thanks. John Soares [EMAIL PROTECTED]

-------- Original Message --------
From: [EMAIL PROTECTED]
Apparently from: [EMAIL PROTECTED]
To: tutor@python.org
Subject: Tutor Digest, Vol 14, Issue 25
Date: Fri, 8 Apr 2005 19:37:37 +0200 (CEST)

Send Tutor mailing list submissions to
tutor@python.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.python.org/mailman/listinfo/tutor
or, via email, send a message with subject or body 'help' to
[EMAIL PROTECTED]

You can reach the person managing the list at
[EMAIL PROTECTED]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Tutor digest..."


Today's Topics:

1. Re: Support (Alberto Troiano)
2. Recursive list checking (joe_schmoe)
3. Re: Support (Kent Johnson)
4. Re: comparison function/built-in needed (joe_schmoe)
5. Re: Recursive list checking (Jeffrey Maitland)
6. Re: Recursive list checking (Jeffrey Maitland)
7. Re: str.split and quotes (Marilyn Davis)
8. Re: Re: Recursive list checking (Kent Johnson)
9. Re: Associate functinos with Dictionary/Class Usage (Luke Jordan)


----------------------------------------------------------------------

Message: 1
Date: Fri, 08 Apr 2005 15:31:42 +0000
From: "Alberto Troiano" <[EMAIL PROTECTED]>
Subject: Re: [Tutor] Support
To: tutor@python.org
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset="us-ascii"

An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20050408/42201ce3/attachment-0001.html

------------------------------

Message: 2
Date: Fri, 08 Apr 2005 16:55:26 +0100
From: joe_schmoe <[EMAIL PROTECTED]>
Subject: [Tutor] Recursive list checking
To: tutor@python.org
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Dear Pythonites

I am looking for a more elegant solution to a piece of code that is too
unwieldy and reptitive. The purpose of the code is for a new addition to
a list to check whether it is a duplicate of a list element already a
member of that list, and if so to regenerate itself randomly and to
perform the same check again until such time as it is unique.
For example, this is what I am currently doing:

=============code block ========================

# generate unique numbers and append to list
nmbr01 = random.randrange( 1, 20 )
nmbr_list.append( nmbr01 )

nmbr02 = random.randrange( 1, 20 )
# check for duplicates and re-generate a number if needed
while nmbr02 in nmbr_list:
nmbr02 = random.randrange( 1, 20 )
nmbr_list.append( nmbr02 )

nmbr03 = random.randrange( 1, 20 )
while nmbr03 in nmbr_list:
nmbr03 = random.randrange( 1, 20 )
nmbr.append( nmbr03 )

================================================

This method works, but increasing the numbers to be appended makes the
code excessively long. I can't see anything in list methods that seems
to do the trick, so anybody want to make a suggestion please?

TIA
/j


------------------------------

Message: 3
Date: Fri, 08 Apr 2005 11:59:24 -0400
From: Kent Johnson <[EMAIL PROTECTED]>
Subject: Re: [Tutor] Support
Cc: tutor@python.org
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Alberto Troiano wrote:
> I tried the code below but the image gets messed up:
>
> import Image
>
> im=Image.open("auto.jpg")
>
> im.show() ###This is to show the image so you can see it
>
> m=im.tostring()
>
> ima=Image.fromstring("RGB",im.size,m)###I tried also with F,RGBA
> and L mode instead of RGB

maybe ima=Image.fromstring(im.mode,im.size,m) will work...

Kent



------------------------------

Message: 4
Date: Fri, 08 Apr 2005 17:10:29 +0100
From: joe_schmoe <[EMAIL PROTECTED]>
Subject: Re: [Tutor] comparison function/built-in needed
To: Kent Johnson <[EMAIL PROTECTED]>
Cc: tutor@python.org
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Kent Johnson wrote:
> joe_schmoe wrote:
>
>> Greetings
>>
>> I am attempting to compare the items in two lists across two criteria
>> - membership and position. For example:
>>
>> list_a = [ 0, 4, 3, 6, 8 ]
>> list_b = [ 1, 8, 4, 6, 2 ]
>>
>> Membership = There are 3 items that are common to both lists, that is
>> 3 items in list_a have membership in list_b (viz: 4, 6, 8);
>
>
> Use sets:
> >>> list_a = [ 0, 4, 3, 6, 8 ]
> >>> list_b = [ 1, 8, 4, 6, 2 ]
> >>> set(list_a).intersection(list_b)
> set([8, 4, 6])
>
>> Position = There is 1 item in list_a that is also in the same position
>> in both lists (viz: 6).
>
>
> Use zip() to iterate two lists in parallel and a list comprehension to
> accumulate the results:
> >>> [ a for a, b in zip(list_a, list_b) if a==b ]
> [6]
>
> or if you want the position of the item use enumerate() to get the index:
> >>> [ i for i, (a, b) in enumerate(zip(list_a, list_b)) if a==b ]
> [3]
>
> Kent
>
>
Hi Kent

Just to confirm: this works just great - thanks!! :)

/j


------------------------------

Message: 5
Date: Fri, 08 Apr 2005 12:11:38 -0400
From: "Jeffrey Maitland" <[EMAIL PROTECTED]>
Subject: [Tutor] Re: Recursive list checking
To: tutor@python.org
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; format=flowed; charset="iso-8859-1"

joe_schmoe writes:

> Dear Pythonites
>
> I am looking for a more elegant solution to a piece of code that is too
> unwieldy and reptitive. The purpose of the code is for a new addition to a
> list to check whether it is a duplicate of a list element already a member
> of that list, and if so to regenerate itself randomly and to perform the
> same check again until such time as it is unique.
> For example, this is what I am currently doing:
>
> =============code block ========================
>
> # generate unique numbers and append to list
> nmbr01 = random.randrange( 1, 20 )
> nmbr_list.append( nmbr01 )
>
> nmbr02 = random.randrange( 1, 20 )
> # check for duplicates and re-generate a number if needed
> while nmbr02 in nmbr_list:
> nmbr02 = random.randrange( 1, 20 )
> nmbr_list.append( nmbr02 )
>
> nmbr03 = random.randrange( 1, 20 )
> while nmbr03 in nmbr_list:
> nmbr03 = random.randrange( 1, 20 )
> nmbr.append( nmbr03 )
>
> ================================================
>
> This method works, but increasing the numbers to be appended makes the
> code excessively long. I can't see anything in list methods that seems to
> do the trick, so anybody want to make a suggestion please?
>
> TIA
> /j
> _______________________________________________
> Tutor maillist - Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

Well I would start by doing something like.

nmbr_list = []
value = int(raw_input("Input the number of items you wish to generate"))

for i in range(value):
if i == 0:
nmbr = random.randrange( 1, 20 )
nmbr_list.append( nmbr01 )
else:
nmbr = random.randrange( 1, 20 )
# check for duplicates and re-generate a number if needed
while nmbr in nmbr_list:
nmbr = random.randrange( 1, 20 )
nmbr_list.append( nmbr )

I hope that helps. or gives you an idea.
Jeff



------------------------------

Message: 6
Date: Fri, 08 Apr 2005 12:17:40 -0400
From: "Jeffrey Maitland" <[EMAIL PROTECTED]>
Subject: [Tutor] Re: Recursive list checking
To: "Jeffrey Maitland" <[EMAIL PROTECTED]>
Cc: tutor@python.org
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; format=flowed; charset="iso-8859-1"

Jeffrey Maitland writes:

> joe_schmoe writes:
>
>> Dear Pythonites
>>
>> I am looking for a more elegant solution to a piece of code that is too
>> unwieldy and reptitive. The purpose of the code is for a new addition to
>> a list to check whether it is a duplicate of a list element already a
>> member of that list, and if so to regenerate itself randomly and to
>> perform the same check again until such time as it is unique.
>> For example, this is what I am currently doing:
>>
>> =============code block ========================
>>
>> # generate unique numbers and append to list
>> nmbr01 = random.randrange( 1, 20 )
>> nmbr_list.append( nmbr01 )
>>
>> nmbr02 = random.randrange( 1, 20 )
>> # check for duplicates and re-generate a number if needed
>> while nmbr02 in nmbr_list:
>> nmbr02 = random.randrange( 1, 20 )
>> nmbr_list.append( nmbr02 )
>>
>> nmbr03 = random.randrange( 1, 20 )
>> while nmbr03 in nmbr_list:
>> nmbr03 = random.randrange( 1, 20 )
>> nmbr.append( nmbr03 )
>>
>> ================================================
>>
>> This method works, but increasing the numbers to be appended makes the
>> code excessively long. I can't see anything in list methods that seems to
>> do the trick, so anybody want to make a suggestion please?
>>
>> TIA
>> /j
>> _______________________________________________
>> Tutor maillist - Tutor@python.org
>> http://mail.python.org/mailman/listinfo/tutor
>
> Well I would start by doing something like.
>
> nmbr_list = []
> value = int(raw_input("Input the number of items you wish to generate"))
>
> for i in range(value):
> if i == 0:
> nmbr = random.randrange( 1, 20 )
> nmbr_list.append( nmbr01 )
> else:
> nmbr = random.randrange( 1, 20 )
> # check for duplicates and re-generate a number if needed
> while nmbr in nmbr_list:
> nmbr = random.randrange( 1, 20 )
> nmbr_list.append( nmbr )
>
> I hope that helps. or gives you an idea.
> Jeff
>
> _______________________________________________
> Tutor maillist - Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

Err just noted that I screwed up on my idea.. here.. is a better party same
idea edited some.

nmbr_list = []
value = int(raw_input("Input the number of items you wish to generate"))

# so this loops the value specified times, as this will add that number to
list too. so a range of 1 - 20 in random order if 20 is the sepcified
number.
for i in range(value):
if i == 0:
nmbr = random.randrange( 1, value )
nmbr_list.append( nmbr )
else:
nmbr = random.randrange( 1, value )
# check for duplicates and re-generate a number if needed
while nmbr in nmbr_list:
nmbr = random.randrange( 1, value )
nmbr_list.append( nmbr )


Jeff

also feel free to ask me more speicifc questions via email if you think they
won't help the cominity at all.



------------------------------

Message: 7
Date: Fri, 8 Apr 2005 09:16:30 -0700 (PDT)
From: Marilyn Davis <[EMAIL PROTECTED]>
Subject: Re: [Tutor] str.split and quotes
To: Kent Johnson <[EMAIL PROTECTED]>
Cc: tutor@python.org
Message-ID: <[EMAIL PROTECTED]>
Content-Type: TEXT/PLAIN; charset=US-ASCII

On Fri, 8 Apr 2005, Kent Johnson wrote:

> Marilyn Davis wrote:
> > Is there a reason to prefer one over the other? Is one faster? I
> > compiled my regular _expression_ to make it quicker.
>
> The only way to know which is faster is to time them both. The timeit module makes it pretty easy to
> do this.
>
> Here is a simple example of using timeit for a different problem; you can adapt it to your own needs:

Thank you so much again.

This will be handy.

Marilyn

>
> d = dict( ((i,i,i), i) for i in range(1000))
>
> def withItems(d):
> for k,v in d.iteritems():
> pass
>
>
> def withKeys(d):
> for k in d:
> d[k]
>
>
> from timeit import Timer
>
> for fn in [withItems, withKeys]:
> name = fn.__name__
> timer = Timer('%s(d)' % name, 'from __main__ import d, %s' % name)
> print name, timer.timeit(1000)
>
>
> Kent
>
> _______________________________________________
> Tutor maillist - Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>

--



------------------------------

Message: 8
Date: Fri, 08 Apr 2005 13:26:30 -0400
From: Kent Johnson <[EMAIL PROTECTED]>
Subject: Re: [Tutor] Re: Recursive list checking
Cc: tutor@python.org
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Jeffrey Maitland wrote:
> joe_schmoe writes:
>
>> Dear Pythonites
>> I am looking for a more elegant solution to a piece of code that is
>> too unwieldy and reptitive. The purpose of the code is for a new
>> addition to a list to check whether it is a duplicate of a list
>> element already a member of that list, and if so to regenerate itself
>> randomly and to perform the same check again until such time as it is
>> unique.
>> For example, this is what I am currently doing:
>> =============code block ========================
>> # generate unique numbers and append to list
>> nmbr01 = random.randrange( 1, 20 )
>> nmbr_list.append( nmbr01 )
>> nmbr02 = random.randrange( 1, 20 )
>> # check for duplicates and re-generate a number if needed
>> while nmbr02 in nmbr_list:
>> nmbr02 = random.randrange( 1, 20 )
>> nmbr_list.append( nmbr02 )
>> nmbr03 = random.randrange( 1, 20 )
>> while nmbr03 in nmbr_list:
>> nmbr03 = random.randrange( 1, 20 )
>> nmbr.append( nmbr03 )
>> ================================================
>> This method works, but increasing the numbers to be appended makes the
>> code excessively long. I can't see anything in list methods that seems
>> to do the trick, so anybody want to make a suggestion please?
>> TIA
>> /j
>> _______________________________________________
>> Tutor maillist - Tutor@python.org
>> http://mail.python.org/mailman/listinfo/tutor
>
>
> Well I would start by doing something like.
> nmbr_list = []
> value = int(raw_input("Input the number of items you wish to generate"))
> for i in range(value):
> if i == 0:
> nmbr = random.randrange( 1, 20 )
> nmbr_list.append( nmbr01 )
> else:
> nmbr = random.randrange( 1, 20 )
> # check for duplicates and re-generate a number if needed
> while nmbr in nmbr_list:
> nmbr = random.randrange( 1, 20 )
> nmbr_list.append( nmbr )
> I hope that helps. or gives you an idea.

The special case for i==0 is not needed, in this case the test for nmbr in nmbr_list will fail and
nmbr will be added to the list.

But if you are trying to get n random elements from range(m) you are probably better off using
random.sample(), I think it does exactly what you want:
>>> random.sample(xrange(10000000), 10)
[274075, 2925710, 7715591, 8236811, 1161108, 5804222, 2385884, 9236087, 5603149, 8473299]

If you actually want *all* elements of the range in random order, use random.shuffle():
>>> l=range(20)
>>> random.shuffle(l)
>>> l
[13, 7, 6, 9, 3, 10, 1, 8, 4, 0, 18, 12, 11, 17, 19, 5, 16, 15, 2, 14]

You might also want to look at random.choice()...

Kent



------------------------------

Message: 9
Date: Fri, 8 Apr 2005 10:37:29 -0700
From: Luke Jordan <[EMAIL PROTECTED]>
Subject: Re: [Tutor] Associate functinos with Dictionary/Class Usage
To: Danny Yoo <[EMAIL PROTECTED]>
Cc: tutor@python.org
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=ISO-8859-1

Yes, Danny - that makes sense. I was getting hung up how to handle the
parens in this part

dict['some'](thing)

all clear now.

:-)

On Apr 7, 2005 4:40 PM, Danny Yoo <[EMAIL PROTECTED]> wrote:
>
>
> On Thu, 7 Apr 2005, Luke Jordan wrote:
>
> > I am looking for a little clarification of how exactly this would work.
> >
> > 1. How do I associate a function to a dict key?
>
> Hi Luke,
>
> We're probably already familiar of values like numbers and strings, and
> how to give them names with variables:
>
> ######
> >>> number = 42
> >>> name = "luke"
> >>> number
> 42
> >>> name
> 'luke'
> ######
>
> 'number' is a name that refers to the value 42, and 'name' is a name (Doh!
> I must use a better variable name next time...) that refers to the value
> "luke".
>
> And we also already know how to make functions and to call them:
>
> ######
> >>> def square(x):
> ... return x * x
> ...
> >>> square(42)
> 1764
> ######
>
> But what happens if we just say "square" at the interpreter?
>
> ######
> >>> square
>
> ######
>
> The value of 'square' is a function value.
>
> And just like any other value, we can assign it to another name:
>
> ######
> >>> anotherNameForSquare = square
> >>> anotherNameForSquare(16)
> 256
> ######
>
> And just like any other value, we can use it as a dictionary value:
>
> ######
> >>> operators = {'^2': square}
> >>> operators['^2']
>
> >>> operators['^2'](4)
> 16
> ######
>
> Does this make sense so far? Please feel free to ask more questions about
> this. Best of wishes!
>
>


--
"Scalpel....blood bucket....priest....next patient."


------------------------------

_______________________________________________
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


End of Tutor Digest, Vol 14, Issue 25
*************************************

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to