woooee 814 Nearly a Posting Maven

If you are not changing the contents of one or both of the lists, then use a tuple instead:

tuple1 = tuple(list2)
woooee 814 Nearly a Posting Maven

Did the shelve module work or do you still want to debug the dictionary class?

woooee 814 Nearly a Posting Maven

Using set.union would give words that are found in both. Again, it is indexed and would be much faster. If you want to use your original idea, then use a dictionary for the words in the base text as the lookup would be 100s of times faster than using 2 lists. This is an example using a dictionary instead of a list.

dic_1 = {}
for word1 in list1:
     if word1 not in dic_1:
          dic_1[word1]=0.
for word2 in list2:
     if word2 in dic_1:
          dic_1[word2] += 1

total_words_found=0
for key in dict_1:
     if dict_1[key] > 0:
          total_words_found += 1
result = float(total_words_found) / (len(list1) + len(list2))
##
##   or
found_set = set_1.union(set_2)
result = float(len(found_set)) / (len(list1) + len(list2))
woooee 814 Nearly a Posting Maven

I'm not sure comparing words will give the best results. If two articles use "and", "the", "a", "of", "to", etc. a lot then they will be deemed similar. If you want to do it that way, then go through each of the two files and place unique words in a set (that is if it is not found in that set). Then use can use the number of words from set_a.difference(set_b) to determine how similar they are. Sets are indexed and so should be hundreds or thousands of times faster.

woooee 814 Nearly a Posting Maven

And if you mean something very simple to time some program once, use datetime.

import datetime
import time
start_time = datetime.datetime.now()
time.sleep(2)
print datetime.datetime.now() - start_time
woooee 814 Nearly a Posting Maven

For God so loved the world that he gave his one and only Son, that whoever believes in him shall not perish but have eternal life.

This does not say anything about the "righteous" being taken up to heaven and the rest will perish in some (un)natural disaster. It is nowhere in the Christian Bible that I know of. The idea itself is full of flaws. One is that heaven, if it does indeed exist (and we don't know if it does or not), is the way that it is because that is the kind of "place" that the angels have made it. To suck a bunch of us mere mortals up all at once would pollute heaven into something much lower, by definition. So it wouldn't be heaven any more. (I know, all it takes is a miracle).

And in the above quote, what does "believes in him" mean. Who is "him". It could be God. It could be Jesus. If could be your own inner soul. Also, there is no time frame. It would make sense, that after another million years of human evolution, the few degenerates that are left would perish. Those would be the people who call themselves "Christian" yet hope for the destruction of others, some of whom are Christian, some not. This is not a good quality for any "human" being to have, let alone a Christian. It goes against everything that Jesus said and stood for. "For God so loved the world". …

woooee 814 Nearly a Posting Maven

You will have to identify the global variables, bet et al. Otherwise, you will be using a second block of memory that is also named bet but local to the function.

if bet  == "quit":
                break
            elif float(bet) <= 0 or float(bet) > x:
                print "Invalid bet."
            else:
                print x, "is a valid amount to bet"
                ##    This would also work
                bet_loop=1
                break

This works much better as a class.

class Betting:
    def __init__(self):
       self.bank = 500.00
       self.bet = 0.00
   
    # defines the betting process within the program
    def bet1(self):
        #set bet loop
        bet_loop=0
        #loop the bet process until the bet is valid
        while bet_loop == 0:
            #tell how much money you have        
            print "You have", self.bank, "dollars in the bank, how much do you bet?"
            #input b            
            self.bet = raw_input("Wager?") 
            #test to make sure that b and x stayed (i did this because it won't work.)            
            print "self.bet in class =", self.bet
            print "self.bank in class=", self.bank
            #checks to see if your bet is valid   
            if self.bet  == "quit":
                break
            elif float(self.bet) <= 0 or float(self.bet) > self.bank:
                print "Invalid bet."
            else:
                print self.bet, "is a valid amount to bet"
                print "if you win you will have %7.2f dollars" % (float(self.bet) +self.bank)
##                bet_loop=1     ## another option
                break 

##=====================================================================
if __name__ == "__main__":
   ## create an instance of the class
   BB=Betting()     ## or instantiate the class (an awful word)
                    ## when you destroy the class do you outstantiate?
   BB.bet1()     ## run this function in the class
   #another …
woooee 814 Nearly a Posting Maven

with everybody but themselves going to hell. It's in the Bible!

Where?

woooee 814 Nearly a Posting Maven

Please add "Solved" to the title. As long as you are accessing each verb, you might as well put them in a dictionary. It is indexed so has faster lookups. If you have sentences with periods, then you will have to use string.replace() to eliminate them. Also consider whether or not there will be upper and lower case letters.

verbs_dic={}
for line in open("verbs.txt", "r"):
   line=line.strip()
   verbs_dic[line.lower()]=0
print verbs_dic

for line in open("apol.txt", "r"):
   line = line.strip()
   words_subs = line.split()
   for word in words_subs:
      if word.lower() in verbs_dic:
         print word, line
woooee 814 Nearly a Posting Maven

Insert some print statements to see what is happening. You may have a LF, "\n", at the end of each aPol_data item in which case you will see an extra empty line when printing old, so it doesn't match any word without one. If this is true, you will have to strip() both the aPol file and data from myFile. Depending on the size of the files, it might run faster if you use a dictionary as the container for aPol_data, split the myFile data into words, and lookup each word in the dictionary.

import string, sys, os
import csv

myFile = open("verbs.txt","r")
data = myFile.readlines()
myFile.close()

aPol = open("apol.txt","r")
aPol_data = aPol.readlines()
aPol.close()

for line in data:
    print "line =", line
    for old in aPol_data:
        print "     old =", old
        if old in line:
            print line
woooee 814 Nearly a Posting Maven

First, the following code will explain what I mean by 2 variables named "i". The second x prints out a different value and a different element for x_list. If this code changed for loop value for x to 1, then the loop would never end in this example because x would never get to 5. It, in fact, repeatedly gives a another block of memory named "x" the value of 1.

x=0
x_list=[ 1, 2, 3, 4, 5 ]
for x in range(0, 5):
   print "\nfor loop x =", x, x_list[x]
   x = 1
   print "     2nd x =", x, x_list[x]
   
##-----  output
for loop x = 0 1
     2nd x = 1 2
     
for loop x = 1 2
     2nd x = 1 2
          
for loop x = 2 3
     2nd x = 1 2
               
for loop x = 3 4
     2nd x = 1 2
                    
for loop x = 4 5
     2nd x = 1 2

If you want to subtract one from each element in x, then it would be something like this, assuming that each element is appended/added to y instead of replacing an existing element

def kopi(x,y):
    for each_el in x:
        print "before subtracting", each_el,
        y.append(each_el-1)
        print "  after subtracting", each_el-1
    print y
    return y

If every element in x is not an integer or float, you will get an error when you try to subtract.

woooee 814 Nearly a Posting Maven

1) You don't return x from the function so it is not visible outside the function.
2) You have multiple variables named "i" (Please don't use, i, l, or o as they look like numbers and there as 23 other letters that work just as well) for i in range (1,len(x)-1): is one, and i=0, i+=1 is the second.
3) The proper way to add to a list is to use append. Following your original idea

def kopi(x,y):
    for j in range (0, len(x)):
        x.append(y[j])        
    print y

You can also use x=y[:]
If you want x[0] + y then you can do
new_x= []
new_x,append(x[0])
new_x += y
If you want x to be y[1]-->y[len(y)], omitting the first element, you can use z=y[1:].
If this doesn't help, then you will have to be more explicit about "doesn't work". That doesn't say much.

woooee 814 Nearly a Posting Maven

Are you on a Mac or Linux? Libfmodex if available for both. It appears that you don't have it installed although it could be installed someplace that is not in the path. Try searching/installing fmodex or libfmodex.

woooee 814 Nearly a Posting Maven

I think Blade321 also wants to ask for input if the numbers don't agree and assign it to the variable x (instead of printing it)

x=0
y= 1234
n=0
while x <> y:
   x = int(raw_input("Enter a number " ))
   n += 1
   if n > 10:
       break
woooee 814 Nearly a Posting Maven

Using a dictionary or set would be faster than "if not key in list" as they are indexed. "If not key in list" has to traverse the list until it finds a key, or until the end is reached if there is no match. It has to do this every time which makes it inefficient for larger lists. A sort may or may not be faster depending on the sort. But there has been no reponse, so I think we may have tried to go too far too fast and just confused the OP.

woooee 814 Nearly a Posting Maven

You can read the data into a list. As stated above, the following statement is already a list, so no need for the copy.
fdata = open(vhdat).readlines()
If there are 544,000 recs and each rec is 100 bytes, that is 54,400,000 bytes (54 megs) of memory. That's very doable in today's world. Memory is thousands of times faster than disk. Anyway, you then want to sort fdata on whatever fields you define as causing a duplicate. Lets call this the index. Process the list one record at a time, and only add to the SQL file if the index does not equal the previous index. I would suspect that the majority of the time spent is with the SQL file. The word "sort" can mean any number of algorithms, and that will be the time consuming part with 544,000 recs. You probably want to go through the list and place all recs less than "x" in a second list, placing non-x in another list for the next pass, sort the list of "x" recs and process. Increase "x" by some increment, etc, etc. The optimum value for x depends on the length of the record, but test the total time it takes on powers of ten, that is 1000 recs per, 10,000 recs per, and 100.000 recs per, which will tell you the range you want to be in. As a very, very general rule, it is much faster sorting 544 batches of 1000 recs than one batch …

woooee 814 Nearly a Posting Maven

Another threading tutorial http://blog.doughellmann.com/2008/01/pymotw-threading_13.html but you probably should be using something like pygame.

woooee 814 Nearly a Posting Maven

Assuming we're all still here of course.

I don't know about you but I will be

I was joking about the earth exploding by then (strange that some people who call themselves religious, wish for that) or maybe that the mother of all computer viruses hasn't been unleashed turning internet use into only advertising and spam generation-much more likely. So what is the next end-of-time event after 2012. First came the new millenium, then 2012. I wonder what's next.

woooee 814 Nearly a Posting Maven

My mistake. I missed that itemY is a list. Given that, you could also use sets as they are indexed. It may be also be more trouble than it's worth but is a good exercise. Also, if you don't want "the" to be found if looking at "theo" then you have to split and compare word to word. Assuming that you want to be case sensitive, that is "a" != "A"

## This Has NOT Been Tested
##modifying  Ene Uran's code
def my_f(modelfilename):
    modelfile = open(modelfilename)
    modelline_list = modelfile.readlines()
    modelfile.close()

    itemY = ["lol", "young", "HoLa", "...", "Yum!",
        ":o)", "blokes", "!!!", "hello"]
    itemY_set=set(itemY)

    for line in modelline_list:
         line_set=set(str(line).split())
         if line_set.intersection(itemY_set):
              print "+1 young"
              # not sure if this is what you want?
              return line  
         else:
              print "-1 old"
woooee 814 Nearly a Posting Maven

Just update the label instead of destroy then re-create. Look for the quote that follows at this link http://effbot.org/tkinterbook/label.htm Hopefully that is what you want. If not, my apologies but a dictionary can still be used as it is just a container for the variable, Tkinter.Label or whatever else you may use. I've never tried doing it this way, but you could
self.input_score_dic[m] = Label(frame,width=6) or whatever
self.input_score_dic[m].destory()
self.input_score_dic[m] = None
self.input_score_dic[m] = Label(frame,width=6) with new text

You can associate a Tkinter variable with a label. When the contents of the variable changes, the label is automatically updated:

v = StringVar()
Label(master, textvariable=v).pack()

v.set("New Text!")

woooee 814 Nearly a Posting Maven

2012 is one of the times for the beginning of the Aquarian age. Pisces (the fish) probably began about 100-200 BC (when Jesus actually lived and ushered in the age-maybe) and so is associated with the Christian religion. In the Bible you find references to the age of Taurus, especially regarding Moses and the golden calf, etc., and I don't remember anything about Aries. We used to get questions about it in the library but not so much anymore. There are several times ranging from the 1960s to 2160 for the age to start. Each age is approximately 2160 years long, so 2160 would the be worst guess because it's just 0 CE to 2160. The 60s is probably too soon. So who knows about 2012. BTW, this is all taken out of context from accounts from before recorded history. These accounts also explain that each age is a sub-period of a larger cycle of 432,000 years. We are about 5,000 years into this larger cycle and so have a long ways to go.

If this thread lasts till the end of 2012, we will have to change the title of it.

Should we all put something in our calendars to post here once a month or so to keep it alive and at the appointed hour have an internet new year's party. Assuming we're all still here of course.

woooee 814 Nearly a Posting Maven

It's time to learn dictionaries as that is the solution to both problems. Give it a try and post back if you can't get something to work. (You are using worstscore twice in the Label but only have to store it once)
self.score_dic["Bill"]=[lastscore, totalscore, worstscore, bestscore]
so self.scores_Bill = self.score_dic["Bill"]
worstscore_Bill=self.scores_Bill[2]
You would never use worstscore_Bill, but would use self.scores_Bill[2] or self.score_dic["Bill"][2]
If you don't use a dictionary, then going beyond a few players gets real tedious real fast.

woooee 814 Nearly a Posting Maven

I saw this solved on another forum. No on wants to waste their time on threads that may have already been solved on another forum. For the future, cross-posted threads will generally get no response.

woooee 814 Nearly a Posting Maven

Perhaps you should state why you want to go around pinging sites. os.popen() is probably not the right tool but that depends on what you are trying to do.

woooee 814 Nearly a Posting Maven

I usually use a dictionary or list

self.input_score_dic={}
for m in range(1, 10):
     self.input_score_dic[m] = Entry(frame,width=6)
woooee 814 Nearly a Posting Maven

You are only checking the first record since you only do one readline(). Add some print statements after the while loop so you can see what you are looking through. If you use readlines(), the entire file will be read into a list

fp = open(modelfilename)
data = fp.readlines()
fp.close()
for modelline in data:
     print "looking for", itemY, "in", modelline
     a = modelline.split()
     if itemY in a:
          print "+1 young"
     else:
          print "-1 old"
woooee 814 Nearly a Posting Maven

Clocked speed must be faster than 5mph and less than 130 mph
What was your clocked speed? 3
Clocked speed must be faster than 5mph

Clocked speed must be faster than 5mph and less than 130 mph
What was your clocked speed? 5

This is indeed how it is supposed to work. The first time the speed was 3, so it prints "Clocked speed must be faster than 5mph", and asks again since the speed wasn't between 5-130. It is the while loop that is doing this, not the if statements. If you enter a speed between 5 & 130 the first time, no message will be printed. It will however print messages as many times as you enter a speed less than 5 or greater than 130.

woooee 814 Nearly a Posting Maven

And the last part should read (I said I was tired)

symbol=substrs[1]  ## not necessary but easier to read
          if symbol in amino_dic:
               amino_dic[symbol] += 1
          else:
               amino_dic[symbol]=1

output will in 21 column,1st column for true false value,others r for 20 amino acids.true false value will be either 1 or -1,and within other 20 coulum one value will be n:1,others will be n:0.n=0,1,2,3..20

Don't understand this statement but it can also be handled with a dictionary of lists, instead of your list of lists.

if symbol not in amino_dic:
               amino_dic[symbol]=[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,]
          amino_dic[symbol] = add one to proper list element
woooee 814 Nearly a Posting Maven

It's late and I'm tired but this is the general idea if I understand correctly

data=["1lghB A i 79.8 H H -24.58",
      "1lghB V i 79.6 H H -22.06",
      "1lghB H i 71.9 H H -19.94"]
for line in data:
     print "\nlooking at", line
     substrs=line.strip().split()
     print  "amino acid =", substrs[1], "and value =", substrs[-1]
     value = abs(float(substrs[-1]))
     if 9.99 < value < 22.01:
          print "greater than 10 and less than 22"
#
# And if you want to keep track of how many hits are found for each
# amino, I would suggest a dictionary with the amino acid symbol 
# as key, containing a simple integer counter, so adding to a
# dictionary the simplest way is:
# (This is still under the if statement)
          if substrs[1] in amino_dic:
               amino_dic += 1
          else:
               amino_dic[substrs[1]]=1

This is what doesn't make sense to me

## what is Z_CORRED
## and you don't define z
for i in Z-CORRED:
if 10.0 <= z <= 22.0:
matches.append([1,i])

And I don't understand all of the print statements. But first, verify that this is the correct way to split the data. Then figure how to store/print it. HTH.

woooee 814 Nearly a Posting Maven

I would remove the if statement in that loop, otherwise you print information twice...

It prints separate statements. One if the speed is less than 5 and another if it is greater than 130. The if/elif = (if) (else+if) so at most only one executes. They are there so that nothing is printed for speeds between 5 and 130.

woooee 814 Nearly a Posting Maven

Note that if someone enters anything other than a number, the program will fail, but It doesn't say anything about testing the input so you are probably OK as is. If you have 2 while() loops in a row, then you will have to enter the data twice, once for each loop.

def ask_speed():
    speed = 0
    while (speed < 5) or (speed > 130):
        print "\nClocked speed must be faster than 5mph and less than 130 mph"
        speed = float(input ("What was your clocked speed? "))
        if speed < 5.0:
             print "Clocked speed must be faster than 5mph"
        elif speed > 130:
             print "You know your radar gun doesn't go that high"
    return speed
woooee 814 Nearly a Posting Maven

Bash will do that for you In Linux. You can also use sys.stdout.write(sys.stdin.read()), although subprocess is now the preferred method. I would guess that on other operating systems it would also be subprocess. This is Doug Hellman's module of the week on subprocess which should get you started http://blog.doughellmann.com/2007/07/pymotw-subprocess.html

woooee 814 Nearly a Posting Maven

Use the show="*" attribute. Also, you are not getting any responses because a Google for "tkinter password" will yield more hits than you can deal with. If this isn't homework, use something found on the web that has already been tested (and is probably written by someone with more Tkinter experience-no offense meant since that includes just about everybody in my case).

woooee 814 Nearly a Posting Maven

You don't have a compiler installed so you can't compile the source. There has to be pre-compiled binaries for the Mac. Search for something like "py-pil" in whatever Mac's use to install software. If you don't find anything then you will have to install XCode developer tools, which contain the compiler, etc (I think). This question is better asked on the Mac forums since it deals with installing software and not Python.

woooee 814 Nearly a Posting Maven

could not call command gcc

Which Linux distro are you using. PIL may be in the repositories for your distro and you can install the normal way. To compile from source you will have to install the libraries used to compile. Again that depends on the distro you are using.

woooee 814 Nearly a Posting Maven

Use endswith. fnmatch is specific to *nix (I think) and so won't work if you are using MS Windows.

if os.path.isfile(fullname):
     # Only work on VOBs and MPGs (for now)
     if filename.endswith('.vob') or filename.endswith('.mpg'):
         f.write('dgindex.exe -IF=[%s] -FO=0 -OM=0 -OF=[%s] -MINIMIZE -EXIT \n' % \
                   (fullname, fullname))
##
##   You could also slice off the end if you have a lot of different endings
ending_tuple=( ".mpg", ".vob" )
ending = filename[-4:]
if ending in ending_tuple:
     ##write to file
woooee 814 Nearly a Posting Maven

AFAIK you use the Python Imaging Library http://www.pythonware.com/library/index.htm Perhaps someone else will know more.

woooee 814 Nearly a Posting Maven

If this is a line of data from the file
28.618382 27.631520 44, followed by
28.618382 27.631520 22
etc, then you can use split() instead of checking for tabs. Also, you can pass a string as a parameter to file open()

##   simulate a file read
data = [ "28.618382   27.631520    44",
          "28.618382	   27.631520    22"]
for line in data:
   substrs = line.split()
   for each_column in substrs:
      print each_column
      print
##
##The T2000901.txt is one of maybe 15 different values
##   using file open
filenames= [ "T2000901.txt", "T2000902.txt", "T2000903.txt"]
for name in filenames:
   print name
   fp=open(name, "r")
   ##   process this file
   fp.close()
woooee 814 Nearly a Posting Maven

Actualy that didnt work. I changed the statements to
if sex == "M" or "m":

An if() statement with an "or" is the same as two if statements (or an elif), so the above equates to
if sex == "M":
elif "m":
I think you want --> if sex=="m"
"if m" is always true, since it is not==zero/False, so this always executes. BTW an if() statesment with an "and" equates to nested if statements. You might want to take another look at the basic design. Python has containers for a reason. You can use a list for the question, and a dictionary for the answer. Next, try adding a third option to the code below to help understand how it works.

literal_list = [ ["Please choose your hero", "(M)ale or (F)emale: "],
                 ["Now for your body build", "Are you (S)lim, (A)verage, (M)uscular, or (H)eavy: "]]
##           dictionary key=M+0 is necessary because you also use M for Muscular
##           The zero relates to the zero element of literal_list=Male
##           M+1 is the "1" element of literal_list=Muscular
answer_dic ={"M0":"A young and adventerous lad out to save the world!",
             "F0":"Look out Lara Croft, there is a new show in town",
             "S1":"Thin and wiry, your (you're) a willow in the wind",
             "A1":"You could pass by him and never notice him, or his gun.",
             "M1":"Tall and hulking, you wouldnt want to run into him in a dark alley",
             "H1":"Hey, big people need love too!"}

j=0
stop=len(literal_list)
while j < …
woooee 814 Nearly a Posting Maven

FWIW this will find all occurrences of a word in a string. Also note that if you are looking for "the" it will give a hit for "then". If you only want the word, you have to search with spaces added, " the " -assuming string.lower() and that punctuation is removed

found=the_string.find(word)
while found > -1:
     print word, "found at location", found
     found=the_string.find(word, found+1)
woooee 814 Nearly a Posting Maven

Note the number of times you have "ord(letter) + rotate". A little algebra

## substituting ascii_val for ord(letter) + rotate
def rotate_word(s,num):
    rotate = num % 26
    newword = ' '
    word=s.upper()
    for letter in word:
        if  ascii_val > 90:     ## ascii_val doesn't exist; this is just for demonstration
            ascii_val = ascii_val - 26
        else:
            ascii_val = ascii_val
        newword = newword + chr(ascii_val)
    return newword

## stripped down it becomes
def rotate_word(s,num):
    rotate = num % 26
    newword = ' '
    word=s.upper()
    for letter in word:
        ascii_val = ord(letter) + rotate
        if  ascii_val > 90:
            ascii_val -= 26
        newword += chr(ascii_val)
    return newword
woooee 814 Nearly a Posting Maven

Without the lambda (which you probably haven't covered)

input_str=raw_input("Enter a string of digits ")

##-------------- Simple way --------------------------------------------------
input_list = [int(x) for x in input_str]
print sum(input_list), input_list

##-------------- Check that it is a digit and sum manually -------------------
input_list=[]
errors=0
for chr in input_str:
   if chr.isdigit():
      input_list.append(int(chr))
   else:
      print "Only the numbers 0 through 9 are allowed"
      errors=1
if not errors:
   total=0
   for x in input_list:
      total += x
   print "total =", total, input_list
woooee 814 Nearly a Posting Maven

I know very little about UTF, but have always seen files opened this way
import codecs
fp = codecs.open( fname, "w", "utf-8" )
I don't know if the filename used has to be a unicode string, and would assume that the records written to the file would be unicode strings.

woooee 814 Nearly a Posting Maven

if count <= count1: Is count1 delared somewhere? If so, which line is the error referencing. Also, use CODE tags, see this post http://www.daniweb.com/forums/announcement114-3.html

woooee 814 Nearly a Posting Maven

I use easyGUI for quick and dirty apps http://www.ferg.org/easygui/

woooee 814 Nearly a Posting Maven

There is no way to tell since the code you use to import is not included. Here is a link to the "Dive Into Python" chapter on import http://diveintopython.org/object_oriented_framework/importing_modules.html

woooee 814 Nearly a Posting Maven

The problem is line 2
fin = open ('E:/words.txt')
You open the file as a global and in line 23 process each record in the file via a for() loop, leaving the pointer at the end of the file. So the second time through you read the file starting at the end of the file, that is no records are read. You can use vegaseat's solution, or move the open into the function and then close the file (which does the same thing as vegaseat). That is somewhat inefficient since you read the same file every time the function is called but if the file is not large it is not much of a difference. has_none() would become

def has_none():

###Function to take a string of letters from the user and search a list of words. 
##The number of words that do not cotain any of the letters will be given###

     contain=0
     notcontain=0

     input=raw_input("Please input a string of letters i.e. jdheu")

     fin = open ('E:/words.txt')
     for line in fin:
          if avoid(line,input)=='True':
               notcontain+=1
          elif avoid(line,input)=='False':
               contain+=1
     fin.close()
     print str(notcontain) +" out of " + str(contain+notcontain) + " did not contain the letters " + input
woooee 814 Nearly a Posting Maven

You can replace the for loop with a function to do this using recursion. While this board will help with homework, not many here will do the whole thing for you.

woooee 814 Nearly a Posting Maven

This is the code modified to do 3 at a time in the way that I think you explained.

test_str="1243#74656453634#6356#56456456#565#1212121#7838483#457"
test_str += "#090#720347###24273#18712#478230478#5711758125671#47464"
test_str += "#74647#46474647#19192938#828##25835#2948284#6010203040#"

test_list=test_str.split("#")
##   subtract one from stop because the last letter is a "#"
stop = len(test_list) - 1
for j in range( 0, stop-2 ):
   for k in range( j+1, stop-1 ):
      for m in range( k+1, stop ):
         numbers_list = [ j, k, m ]
         ctr=0
         final_str=""
         while ctr < stop:
            final_str += test_list[ctr]
            if ctr in numbers_list:     ## or ==j, or ==k, or == m if you want
               final_str += "@"
            else:
               final_str += "#"        ## or "!" if you want
            ctr += 1
         print final_str
         print j, k, m, "Hello World\n"
woooee 814 Nearly a Posting Maven

You can split on the "#" and do a single replace for both characters if that helps That's a single pass through the number string for the split() and a single join to put it back together instead of multiple lookup passes to find and replace each number. Instead of the "while()", a "for each_number in test_list", keeping the ctr as well, might be slightly faster over a very large data set since you will not have to find a specific member of the list i.e. each_number is used instead of test_list[ctr].

test_str="1243#74656453634#6356#56456456#565#1212121#7838483#457"
test_str += "#090#720347###24273#18712#478230478#5711758125671#47464"
test_str += "#74647#46474647#19192938#828##25835#2948284#6010203040#"

numbers_list=[ 1, 3, 6, 9, 10]
test_list=test_str.split("#")
stop = len(test_list)
ctr=0
final_str=""
while ctr < stop:
   final_str += test_list[ctr]
   if ctr in numbers_list:
      final_str += "@"
   else:
      final_str += "!"
   ctr += 1
print final_str