[Tutor] CBNC control loop.

Tesla Coil tescoil@rtpro.net
Sun, 19 Mar 2000 12:21:20 -0600


# Desired result:  keyword TOMATO generates idxlist
# [3, 9, 15, 21, 2, 8, 14, 20, 26, 1, 7, 13, 19, 25, 5, 11, 17, 23,
# 0, 6, 12, 18, 24, 4, 10, 16, 22]
# Close-But-No-Cigar control loop results in:
# [9, 15, 21, 27, 8, 14, 20, 26, 32, 7, 13, 19, 25, 31, 11, 17, 23,
# 29, 6, 12, 18, 24, 30, 10, 16, 22, 28]

import string
keystring = raw_input ('keyword please: ')
keystring = string.upper(keystring)
keylist = list(keystring)
seqlist = []
message = string.uppercase

def unstray(listinput):
    for stray in listinput:
        if stray not in string.uppercase:
            listinput.remove(stray)

def keysequence(alphakey):
    for letter in range(len(string.uppercase)):
        for item in range(len(alphakey)):
            if string.uppercase[letter]==alphakey[item]:
                seqlist.append(item)

unstray(keylist)
keysequence(keylist)

idxlist=[]

# CBNC control loop here:
for n in range(len(seqlist)):
    idxpos = seqlist[n]
        while idxpos <= len(message):
            idxpos = idxpos+len(seqlist)
            idxlist.append(idxpos)

print idxlist