[Tutor] (no subject)

2005-12-05 Thread david



hello everyone, and thanks for your help and 
guidance so far.
amazingly enough, something i thought would be 
simple has turned out to be not simple.
i have a sword that i want to wield. as i have it 
here, i think i am wielding whatever string i type
as argument to wield. so i guess i need to pass 
wield an object somehow instead of a string.
can anyone point in the right direction? 

 
class Player:    def 
__init__(self,name):    self.name = 
name    self.location = 
None    self.inventory = 
[]    self.wielded = 
None    self.headwear = 
None   def 
wield(self,what):    print 
type(what)    print 'you 
wield',what    self.wielded = 
what  
def do(self):    cmd = 
string.split(raw_input('>'))    
verb = cmd[0]    if len(cmd) > 
1:    target 
= cmd[1]    
    if verb == 
'l':    
self.look()    elif verb in 
['n','s','e','w']:   
    
self.move(verb)    elif verb == 
'quit':    
sys.exit()    elif verb == 
'i':    print 
'wielded',self.wielded    
print 'on head', 
self.headwear    
for a in 
self.inventory:    
print a.name elif verb 
== 
'wield':    
self.wield(target) else:    
print 'what?'
 
class Thing:    def 
__init__(self,name):    self.name = 
name    self.uponwield = 
''    p = 
Player('david')
 
 
 
sord = Thing('sword')sord.uponwield = 'the 
sword glows 'hat = 
Thing('hat')p.inventory.append(sword)p.inventory.append(hat)
 
 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] files - strings - lists (continued)

2005-12-05 Thread Andrzej Kolinski

  I used Kent's hints and suggestions
but now I'm facing a problem of how to calculate final results from the
retrieved data. My script, at this stage, opens _all_ game results files,
gets an individual player's name, calculates his score and keeps the number
of boards played. It does it per _each_ _game_ _individually_. What I would
like to do is to calculate his ranking as a: (sum of all scores)/(sum of
all boards).

I have no clue how to combine results
from, let's say, 3 games and use it for the above calculations. Below are:
the copy of the script (under construction) and the sample of the data
available:

#
import glob, string

resultsFileName = 'butler.txt'
resultsFile = open(resultsFileName,"w")
resultsFile.write('--\nImie
i Nazwisko\t\tBUTLER\n-\n')
 
for f in glob.glob("*.sbk"):
# Get all text files and loop over them
   try:
      filecontents =
open(f,'r')
      filecontents.next()
      filecontents.next()
      header = filecontents.next().split()
      hands = int(header[2])
      rounds = int(header[3])
      boards = hands*rounds

      filecontents.next()
   except IOError:
      # If something
went wrong, ignore this file
      continue
   allScores = {} 
   try:    # you
don't say how you know the end of the names, I just run to the end of data
    while True:
        names =
filecontents.next().strip().split()
        player1
= names[0]
        player2
= names[2]
        
        filecontents.next()
   # skip line after name
        scores =
[ int(filecontents.next().split()[2]) for i in range(rounds) ]
        tScores
= 0
        for i in
scores:
           
iScore = float(i)
           
tScores = float(sum(scores))

        allScores.setdefault(player1,
[]).append((tScores, boards))
        allScores.setdefault(player2,
[]).append((tScores, boards))
    
   except: # no more lines
       if filecontents.next()
== '1,1':
          pass
   
   for player1, tScores in
allScores.items():
       print player1,
tScores
       score = tScores[0][0]
       played =
tScores[0][1]
       butler =
score/played
       #print ("%1.4f")
%butler
       
       line = "%s\t\t%1.4f"
%(player1, butler)
       #print line
       resultsFile.write(line
+ '\n')
filecontents.close()
resultsFile.close()

Chrabalowski [(21.0, 24)]
Kowalski [(-8.0, 24)]
Kolinski [(31.0, 24)]
.
Chrabalowski [(45.0, 25)]
Orlicka [(-27.0, 25)]
KempaM [(5.0, 25)]

Chrabalowski [(-23.0, 25)]
Lukasik [(-24.0, 25)]
Szczerbowski [(31.0, 25)]

As you can see Chrabalowski played in
all three games. His current score should be calculated like this:

finalButler = (21.0 + 45.0 -23.0)/(24
+ 25 + 25), which is 0.5811 by the way.

Is the individual db appropriate for
this or I should be looking for a dictionary type format. I am lost.

        _/_/      _/     _/
   _/       _/  _/   _/
  _/_/_/_/  _/ _/
 _/      _/  _/   _/
_/     _/  _/      _/

Andrzej Kolinski






Kent Johnson <[EMAIL PROTECTED]>

Sent by: [EMAIL PROTECTED]
24/11/2005 08:40 PM




To



cc
tutor@python.org


Subject
Re: [Tutor] files - strings - lists








Andrzej Kolinski wrote:
> 
>   OK, I made some progress I think. I added a few lines to Kent's
script 
> to get closer what I really am after:

Congratulations! See some notes below.

> 
> ==
> lines = open('liga050926.sbk')   # to get the data from a real
file
> 
> #lines = iter(data)  # getting data from a string, you don't
need this 
> when reading a file
> 
> lines.next()    # skip two headers
> lines.next()
> 
> header = lines.next().split()
> hands = int(header[2])
> rounds = int(header[3])
> boards = hands*rounds
> 
> lines.next()
> 
> 
> allScores = {}  # accumulate scores into a dictionary whose key
is the name
> 
> # Now we can process the names and scores in a loop
> try:    # you don't say how you know the end of the names,
I just run to 
> the end of data
>     while True:
>         names = lines.next().strip()
>         player1 = names.split()[0]
>         player2 = names.split()[2]

This could be
        names = lines.next().strip().split()
        player1 = names[0]
        player2 = names[2]
or even
        player1, player2 = lines.next().strip().split('
- ')
>        
>         lines.next()    # skip line
after name
>         scores = [ int(lines.next().split()[2])
for i in range(rounds) ]
>         tScores = 0
>         for i in scores:
>             iScore = float(i)
>             tScores = tScores + iScore

This could be
  tScores = float(sum(scores))
> 
>         allScores[player1] = tScores/boards
>         allScores[player2] = tScores/boards
>    
> except: # no more lines
>     if lines.next() == '1,1':
>         pass

I'm not sure what the two lines above are doing? It looks like you don't
have a good way to detect the end of the data and you just catch 

[Tutor] distutils python 2.4.2 winxp, microsoft visual studio 2005 problem

2005-12-05 Thread Pujo Aji
Hello,I try to call setup build and found this problem:running buildrunning build_ext*** Failed: error: The .NET Framework SDK needs to be installed before building extensions for Python.I have .NET Framework SDK already.
Is there anyone experiance this problem ?I also found some information about this : http://www.vrplumber.com/programming/mstoolkit
But I think this is only for .NetFramework 1.1 and visual studio 7I have Visual studio express 2005 which use .NetFramework 2.0Can anybody helps?Thankspujo
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] (no subject)

2005-12-05 Thread Roberts, Alice








Good morning,

 

Does anyone know of something that will copy a directory
tree, but only for files with a specific extension?  I found 


 
  
  copytree(
  
  
  src, dst[,
  symlinks])
  
 


, but I wasn’t sure how to assign the src to the
string, ie) \\server\share\*.xls.

 

Thanks,

Alice.

 

 






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


Re: [Tutor] (no subject)

2005-12-05 Thread Kent Johnson
Roberts, Alice wrote:

> Good morning,
>
> Does anyone know of something that will copy a directory tree, but 
> only for files with a specific extension? I found
>
> *copytree*(
>
>   
>
> /src, dst/[/, symlinks/])
>
> , but I wasn’t sure how to assign the src to the string, ie) 
> \\server\share\*.xls.
>
Alice,

shutil.copytree() won't do what you want, but you might consider making 
a modified copy for your own use. It is a pretty simple function and the 
comments even encourage using it as an example to do what you want. You 
can find the source in the Lib directory of your Python installation.

Kent

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


Re: [Tutor] Problems padding a string with 0's while deconcatonating

2005-12-05 Thread Kent Johnson
Josh Yagy wrote:

>I have the following code:
>
>def binaryString(b, n):
>   s=[]
>   j=0
>   while j < len(b):
>   temp = b[j:j+n]
>   s = s + [ temp ]
>   j = j + n
>   return s
>
>which works for all intents and purposes, but I can't figure out a way to get 
>it to pad the left of the string with zeros so that each of the subsets is n 
>bits  long. As is, it will deconcatonate a given string into n-substrings, but 
>not all of the substrings are n bits long. Any help would be greatly 
>appreciated and sorry again if I didn't include anything I should. 
>
Josh,

I don't think I understand the problem. When I try your function I get
b= '01010011000111'
print binaryString(b, 4) -> ['0101', '0011', '0001', '1100', '0011', '11']

How does this differ from what you want? I am not losing any leading 
zeros, just the last substring is short.

BTW your function can be written much more compactly. I'll show you how 
in a few steps.

First, notice that the sequence of values in j can be generated with the 
range() function, e.g.
 >>> range(0, len(b), 4)
[0, 4, 8, 12, 16, 20]

This lets you replace the calculation of j with a simple for statement:

def binaryString2(b, n):
s=[]
for j in range(0, len(b), n):
temp = b[j:j+n]
s = s + [ temp ]
return s

Next, use list.append() to add to s and get rid of temp:

def binaryString3(b, n):
s=[]
for j in range(0, len(b), n):
s.append(b[j:j+n])
return s

Now this can be easily replaced with a single list comprehension:

def binaryString4(b, n):
return [b[j:j+n] for j in range(0, len(b), n)]

(This version appears in the Python Cookbook at 
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/425044)

Kent

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


Re: [Tutor] RPG wielding

2005-12-05 Thread Danny Yoo


> hello everyone, and thanks for your help and guidance so far. amazingly
> enough, something i thought would be simple has turned out to be not
> simple. i have a sword that i want to wield. as i have it here, i think
> i am wielding whatever string i type as argument to wield. so i guess i
> need to pass wield an object somehow instead of a string. can anyone
> point in the right direction?

Your player's inventory is a list of items.  One way to make wield() work
right is to hunt through your inventory to see what item matches the
'what'.

Good luck!


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


Re: [Tutor] (no subject)

2005-12-05 Thread Alan Gauld
> i guess i need to pass wield an object somehow instead of a string.
> can anyone point in the right direction?

AS ever converting strings to objects is a job for a doictionary. And 
remember that classe3s are objects too.

So simply register each class you define in a dictionary of classes against 
their name

classes = {'Room':Room, 'Player': Player, 'Sword':Sword,...}

class Player:
   def wield(self,what):
 print type(what)
 print 'you wield',what
 self.wielded = classes[what]()   # an instance of what...

HTH,

Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld


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


Re: [Tutor] script run problem

2005-12-05 Thread Alan Gauld
Hi Kishra,

In the words of the old joke(*) why not just 'get out and get back in' and
see if that fixes it? In other words I'd try a reinstall of Python, it looks
like something has gone missing or got corrupted...

Alan G.

(*)Three guys are in a car that breaks down. The first says "I'm an
Electrical Engineer, I bet it's the electrics", jumps out and starts 
checking
the wiring. The second guy says "I'm a mechanical engineer, it's probably
the engine" and gets out to check the gaskets. The third guy says
"I'm a software engineer, why don't we just get out of
the car then get back in and see if that fixes it?"


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


Re: [Tutor] Problems padding a string with 0's while deconcatonating

2005-12-05 Thread Josh Yagy
Wow, that code is much more compact, thanks for the help! But as far as the 
original question goes, I think I worded my problem wrong. The output you got 
with your binary string is almost what I Want, but not quite. I need each 
subset of binary strings to be n bits long (in the dummy problem you ran, 4 
bits). The last subset is two bits short, but for the sake of the cryptosystem, 
I can't pad it with zeros at the right, I need to pad it to the left. for 
instance:
Your output was:
 print binaryString(b, 4) -> ['0101', '0011', '0001', '1100', '0011', '11']
What I'm looking for is for the output to be:
print binaryString(b, 4) -> ['0001', '0100', '1100', '0111', '', '']

notice that my desired output is the same as yours, only all the bits are moved 
back two places to fill up the last subset, and the extra space is filled with 
0's in the first subset. 

Thanks again for the help

-Original Message-
From: Kent Johnson <[EMAIL PROTECTED]>
Date: Mon, 05 Dec 2005 13:05:46 -0500
Subject: Re: [Tutor] Problems padding a string with 0's while deconcatonating

Josh Yagy wrote:

>I have the following code:
>
>def binaryString(b, n):
>   s=[]
>   j=0
>   while j < len(b):
>   temp = b[j:j+n]
>   s = s + [ temp ]
>   j = j + n
>   return s
>
>which works for all intents and purposes, but I can't figure out a way to get 
>it to pad the left of the string with zeros so that each of the subsets is n 
>bits  long. As is, it will deconcatonate a given string into n-substrings, but 
>not all of the substrings are n bits long. Any help would be greatly 
>appreciated and sorry again if I didn't include anything I should. 
>
Josh,

I don't think I understand the problem. When I try your function I get
b= '01010011000111'
print binaryString(b, 4) -> ['0101', '0011', '0001', '1100', '0011', '11']

How does this differ from what you want? I am not losing any leading 
zeros, just the last substring is short.

BTW your function can be written much more compactly. I'll show you how 
in a few steps.

First, notice that the sequence of values in j can be generated with the 
range() function, e.g.
 >>> range(0, len(b), 4)
[0, 4, 8, 12, 16, 20]

This lets you replace the calculation of j with a simple for statement:

def binaryString2(b, n):
s=[]
for j in range(0, len(b), n):
temp = b[j:j+n]
s = s + [ temp ]
return s

Next, use list.append() to add to s and get rid of temp:

def binaryString3(b, n):
s=[]
for j in range(0, len(b), n):
s.append(b[j:j+n])
return s

Now this can be easily replaced with a single list comprehension:

def binaryString4(b, n):
return [b[j:j+n] for j in range(0, len(b), n)]

(This version appears in the Python Cookbook at 
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/425044)

Kent

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



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


Re: [Tutor] Problems padding a string with 0's while deconcatonating

2005-12-05 Thread Ismael Garrido
Josh Yagy wrote:

>Wow, that code is much more compact, thanks for the help! But as far as the 
>original question goes, I think I worded my problem wrong. The output you got 
>with your binary string is almost what I Want, but not quite. I need each 
>subset of binary strings to be n bits long (in the dummy problem you ran, 4 
>bits). The last subset is two bits short, but for the sake of the 
>cryptosystem, I can't pad it with zeros at the right, I need to pad it to the 
>left. for instance:
>Your output was:
> print binaryString(b, 4) -> ['0101', '0011', '0001', '1100', '0011', '11']
>What I'm looking for is for the output to be:
>print binaryString(b, 4) -> ['0001', '0100', '1100', '0111', '', '']
>
>notice that my desired output is the same as yours, only all the bits are 
>moved back two places to fill up the last subset, and the extra space is 
>filled with 0's in the first subset. 
>
>Thanks again for the help
>

Why don't you pad it before processing?

def padleft(b, bits):
bitsshort = len(b)%bits
if bitsshort:  #so that if len(b) == bits you don't get extra 0s
amount = bits - bitsshort
return "0"*amount + b
return b

 >>> padleft("10011", 5)
'10011'
 >>> padleft("101101", 4)
'00101101'
 >>> padleft("1010101", 6)
'01010101'

HTH!
Ismael
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Problems padding a string with 0's while deconcatonating

2005-12-05 Thread John Fouhy
On 06/12/05, Josh Yagy <[EMAIL PROTECTED]> wrote:
> Wow, that code is much more compact, thanks for the help! But as far as the 
> original
> question goes, I think I worded my problem wrong. The output you got with 
> your binary string
> is almost what I Want, but not quite. I need each subset of binary strings to 
> be n bits long (in
> the dummy problem you ran, 4 bits). The last subset is two bits short, but 
> for the sake of the
> cryptosystem, I can't pad it with zeros at the right, I need to pad it to the 
> left. for instance:

Perhaps you could pad the original string!

How much do we pad it by? Well, if n is the word size, we're not
interested in how many complete chunks of n bits there are.  We're
only interested in how many are left over, once we cast out all
complete pieces.  This is equivalent to asking for the remainder,
after dividing the length by n.

eg:

>>> b = '01010011010110101101101'
>>> len(b)
23
>>> len(b)//4# The // means we want integer division, not real division.
5
>>> len(b)-4*(len(b)//4)
3

So, if we split b into 4 bit pieces, there will be 5 of them, and 3
bits left over.  But there's an easier way to do that calculation ---
the modulo operator:

>>> len(b) % 4
3

That's how many extra bits we have, so we can subtract that from n to
get the number of '0's we need to pad with.

Does that help?

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


[Tutor] How to Pass lists by value

2005-12-05 Thread Hans Dushanthakumar
 
Hi folks,
   How do I pass a list by value to a function.

The foll: snippet of code produces the output as shown:

Code:
-
def junk(x):
x.append("20")
return x

a = ["10"]
b = junk(a)

print b
print a


Output:
---
>>> 
b =  ['10', '20']
a =  ['10', '20']

This indicates that the variable "a" was passed by reference because the
function alters its value in the main script.

However, the following code produces a slightly diff output:

Code:
-

def junk(x):
x = "30"
return x

a = ["10"]
b = junk(a)

print "b = ", b
print "a = ", a

Output:
---
>>> 
b =  30
a =  ['10']

In this case, "a" seems to be passed by value, because the value is
unchanged even after the call to the function.


Question is, in the 1st scenario, how do I forcefully pass the variable
by value rather than reference. Why is there a difference between the
two scenarios?

Cheers
Hans
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to Pass lists by value

2005-12-05 Thread Hans Dushanthakumar



Thanks guys
 
Yes either of the foll solves the 
problem:
 
b = junk(copy.copy(a))
 OR
b = 
junk(a[:])
 
 
Why is there a difference between the way the 
two lines (x.append("20")  and x = "30") are handled within a 
function?
 


From: Adam [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, 6 December 2005 1:49 p.m.To: Hans 
DushanthakumarSubject: Re: [Tutor] How to Pass lists by 
value
On 06/12/05, Hans Dushanthakumar <[EMAIL PROTECTED]> 
wrote:

Hi 
  folks,   How do I pass a list by value to a function.The 
  foll: snippet of code produces the output as 
  shown:Code:-def 
  junk(x):x.append("20")return 
  xa = ["10"]b = junk(a)print bprint 
  aOutput:--->>>b =  ['10', 
  '20']a =  ['10', '20']This indicates that the variable 
  "a" was passed by reference because the function alters its value in the 
  main script.However, the following code produces a slightly diff 
  output:Code:-def junk(x):x 
  = "30"return xa = ["10"] b = 
  junk(a)print "b = ", bprint "a = ", 
  aOutput:--->>>b =  30a 
  =  ['10']In this case, "a" seems to be passed by value, 
  because the value is unchanged even after the call to the 
  function.Question is, in the 1st scenario, how do I forcefully 
  pass the variableby value rather than reference. Why is there a difference 
  between thetwo scenarios? 
  CheersHans___Tutor 
  maillist  -  Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor 
  
 def junk(x):   x.append("20")  
 return xa = ["10"]b = junk(a[:])That should give you 
what you're looking for a[:] will pass the values of 
a.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to Pass lists by value

2005-12-05 Thread John Fouhy
On 06/12/05, Hans Dushanthakumar <[EMAIL PROTECTED]> wrote:
>
> Thanks guys
>
> Yes either of the foll solves the problem:
>
> b = junk(copy.copy(a))
>
>  OR
>
> b = junk(a[:])

One thing you should be aware of --- these will both do a "shallow copy".

Example:

>>> lists = [[], [], [], []]
>>> lists2 = lists[:]
>>> lists.append('foo')
>>> lists, lists2 # This shows that lists and lists2 are different.
([[], [], [], [], 'foo'], [[], [], [], []])
>>> lists[0].append(13)
>>> lists, lists2 # Oops, but lists[0] and lists2[0] are the same!
([[13], [], [], [], 'foo'], [[13], [], [], []])

> Why is there a difference between the way the two lines (x.append("20")  and
> x = "30") are handled within a function?

x = '30' will create a new (local) variable x and give it the value '30'.

x.append('20') will call the .append() method on x.  Calling this
method has the side effect of changing the list x points to.

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


Re: [Tutor] How to Pass lists by value

2005-12-05 Thread Kent Johnson
Hans Dushanthakumar wrote:

> Thanks guys
>  
> Yes either of the foll solves the problem:
>  
> b = junk(copy.copy(a))
>  OR
>
> b = junk(a[:])

These work because they make a copy of a and pass (a reference to) the 
copy to the function.

>   Why is there a difference between the way the two lines 
> (x.append("20")  and x = "30") are handled within a function?

Because they are doing different things. x.append("20") calls a method 
on the object bound to the name x. The method mutates the object, so it 
now has a new value. x = "30" binds the name x to a new object, the 
string "30". This binding happens in the local namespace so it doesn't 
affect the value seen by the caller.

You have to change how you think about variables. In Python, a variable 
is not a storage location into which values are put, it is a reference 
to an object - a name given to an object. Assignment binds a name to a 
value.

When you call a function, the names of the formal parameters are bound 
to the values passed in to the function. Parameters are *always* passed 
by reference. The names inside the function are bound to the same 
objects as the names outside the function, so if you call a mutating 
method on the object, like list.append(), the change will be seen 
externally. If you rebind the name inside the function, this has no 
effect on the bindings external to the function.

I hope this helps. There is a fundamental shift in the way you think 
about names that is needed to grok Python. Once you get it much will 
become clearer - The Zen of Python says, "Namespaces are one honking 
great idea -- let's do more of those!" so it's important to understand 
namespaces :-)

This may help:
http://effbot.org/zone/python-objects.htm

Kent

>
>  
> 
> *From:* Adam [mailto:[EMAIL PROTECTED]
> *Sent:* Tuesday, 6 December 2005 1:49 p.m.
> *To:* Hans Dushanthakumar
> *Subject:* Re: [Tutor] How to Pass lists by value
>
> On 06/12/05, *Hans Dushanthakumar* <[EMAIL PROTECTED] 
> > wrote:
>
>
> Hi folks,
>How do I pass a list by value to a function.
>
> The foll: snippet of code produces the output as shown:
>
> Code:
> -
> def junk(x):
> x.append("20")
> return x
>
> a = ["10"]
> b = junk(a)
>
> print b
> print a
>
>
> Output:
> ---

> b =  ['10', '20']
> a =  ['10', '20']
>
> This indicates that the variable "a" was passed by reference
> because the
> function alters its value in the main script.
>
> However, the following code produces a slightly diff output:
>
> Code:
> -
>
> def junk(x):
> x = "30"
> return x
>
> a = ["10"]
> b = junk(a)
>
> print "b = ", b
> print "a = ", a
>
> Output:
> ---

> b =  30
> a =  ['10']
>
> In this case, "a" seems to be passed by value, because the value is
> unchanged even after the call to the function.
>
>
> Question is, in the 1st scenario, how do I forcefully pass the
> variable
> by value rather than reference. Why is there a difference between the
> two scenarios?
>
> Cheers
> Hans
> ___
> Tutor maillist  -  Tutor@python.org 
> http://mail.python.org/mailman/listinfo/tutor
> 
>
>
>  
> def junk(x):
>x.append("20")
>return x
>
> a = ["10"]
> b = junk(a[:])
>
> That should give you what you're looking for a[:] will pass the values 
> of a.
>
>
>
>___
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor
>  
>


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


[Tutor] terminology

2005-12-05 Thread david



suppose you have a list of words and you 
want to unambiguously identify
each word in the list with the shortest number of 
characters.
for instance a list like : kill, kiss, 
take
i would want to get take just by typing 
t.
but you would have to type kil or kis to get kill 
or kiss.
where should i start googling? is this a matter of 
sorting?
i was thinking of trees for some reason. 

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


Re: [Tutor] terminology

2005-12-05 Thread John Fouhy
On 06/12/05, david <[EMAIL PROTECTED]> wrote:

> suppose you have a list of words and you want to unambiguously identify
> each word in the list with the shortest number of characters.
> for instance a list like : kill, kiss, take
> i would want to get take just by typing t.
> but you would have to type kil or kis to get kill or kiss.
> where should i start googling? is this a matter of sorting?
> i was thinking of trees for some reason.

Look for tries :-) http://en.wikipedia.org/wiki/Trie or
http://www.nist.gov/dads/HTML/trie.html

I think there's a couple of good python implementations around that
you could google for..

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


Re: [Tutor] terminology

2005-12-05 Thread Danny Yoo

> > suppose you have a list of words and you want to unambiguously identify
> > each word in the list with the shortest number of characters.
> > for instance a list like : kill, kiss, take
> > i would want to get take just by typing t.
> > but you would have to type kil or kis to get kill or kiss.
> > where should i start googling? is this a matter of sorting?
> > i was thinking of trees for some reason.
>
> Look for tries :-) http://en.wikipedia.org/wiki/Trie or
> http://www.nist.gov/dads/HTML/trie.html
>
> I think there's a couple of good python implementations around that you
> could google for..

Hi David,

Alternatively, the 'bisect' module might be "good enough".

http://www.python.org/doc/lib/module-bisect.html

bisect_left() will get us quickly to the right leftmost position (or the
leftmost right position?  *grin*), if we assuming the list of words is
sorted.

For example:

###
>>> import bisect
>>> words = [x.strip() for x in open('/usr/share/dict/words').readlines()]
>>> words.sort()
>>> bisect.bisect_left(words, 'kiss')
114279
>>> words[114280]
'kissability'
>>> words[114281]
'kissable'
>>> words[114282]
'kissableness'
###

The idea is that we can just continue marching across our sorted list of
words till we stop finding candidates, once we find our starting position.

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


[Tutor] MS ODBC

2005-12-05 Thread Gregorius Gede Wiranarada
hello,
how can i connect python to read data from ms access or ms foxpro? 

regards,
Gregor 

___
Dibuka pendaftaran Program Magister dan Double Degree Pascasarjana UAJY
(MM - MTF atau sebaliknya; M.Hum - MTF; M.Hum - MM; MTS. - MM).
Penerimaan mahasiswa setiap Mei, September dan Januari. 


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