Hi,
here is an example of using the random function I am working at right now (it randomizes (is that a word?) every word in a list):
import string
import random
from itertools import ifilter, ifilterfalse

def reinterpolate(word):
    #thanks to Raymond Hettinger (taken from the Python list)
    word = list(word)
    random.shuffle(word)

    isvowel = dict.fromkeys('aeiouy').has_key
    vowels = ifilterfalse(isvowel, word)
    consonants = ifilter(isvowel, word)

    result = []
    for v, c in map(None, vowels, consonants):
            if c:
                result.append(c)
            if v:
                result.append(v)
    # added stuff to keep the dot at the end of every sentence in the list (dp)
    result = ''.join(result)
    if result.find('.') != -1:
        result = result.replace('.', '') + '.'
        return ''.join(result)
    else:
        return ''.join(result)

def gib(mystring):
    print 'This is the original: ', mystring
    mylist = string.split(mystring)
   
    newlist = []
    for i in range(len(mylist)):
                i = reinterpolate(mylist[i])
                newlist.append(i)
               
    newstring = ' '.join(newlist)
    cap = ". ".join([s.capitalize() for s in newstring.split(". ")])
    print 'This is the scramble: ', cap
   
# example usage   
if __name__ == "__main__":
  mystring = "harry is a strange guy. so is his sister, but at least she is not a guy. i am."
  gib(mystring)

Maybe it helps.
regards,
Dimitri

On 6/30/05, Nathan Pinno <[EMAIL PROTECTED]> wrote:


  Hi all,

  Does Python have a random function? If so, can you show me an example
using it?

  Thanks,
  Nathan Pinno
  http://www.npinnowebsite.ca/



--


----------------------------------------------------------------
     Posted via UsenetRevolution.com - Revolutionary Usenet
** HIGH RETENTION ** Specializing in Large Binaries Downloads **
                 http://www.UsenetRevolution.com
--
http://mail.python.org/mailman/listinfo/python-list



--
Please visit dimitri's website: www.serpia.com
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to