[Tutor] transposing [n, [e],[s[te]],[d]] sequences

kevin parks kp87@lycos.com
Sat, 16 Feb 2002 22:32:10 +0900


# Here is the type of thing i can write pretty swiftly now:

def Xpose(seq,n, oct=12, sort_flag=0):
    ''' take a sequence and tranpose it modulo some number
    '''
    mylist=[]
    for i in seq:
        x = (i+n)%oct
        mylist.append(x) # to append or extend?
    if sort_flag:
        mylist.sort() # to sort or not sort
    return mylist

#-- (i am at an internet cafe with no interpreter so there could
# be a type, but i hope not, Imaginary session follows:

>>> x = [0, 2, 4, 5, 7, 9, 11]
>>> c = Xpose(x, 4, 12, 0)
>>> c
[4, 6, 8, 9, 11, 1, 3]
>>> d = Xpose(x, 4, 12, 1) # sorted now
>>> d
[1, 3, 4, 6, 8, 9, 11]

# cool. It works, and just in case you are curious i just turned a
# C major scale into E major

# Problem: how do i make something like this work for nested sequences? since sometimes we will have lists of lists or (god help us) list of *gasp* tuples...

# can anyone take me through the steps? to *upgrade this simple little
# diddy to something more rubust and verstile?

cheers,

-kevin





Check out Cupid School where you will learn from Matchmaker's
best and brightest. Good Luck!

http://ecard.matchmaker.com/cupid0202/cupid0202.html