sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #15240
Re: [Question #217327]: how to create x lists from a given list, each new list created by removing an element
Question #217327 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/217327
Summary changed to:
how to create x lists from a given list, each new list created by removing an element
Description changed to:
--- new version of already existing question
https://answers.launchpad.net/sikuli/+question/216288
----------------------------------------------------------------------------
The original problem is to choose randomly a color from a list of
colors, until all colors are used without repetition .(sort of Paint
program)
alist = ('1','2','3','4','5') #"1" already exists, the others should be created one by one
when the for loop runs.
x = 1
###############HOW TO INSERT A VARIABLE (X=1) IN A LIST? GOOGLING THE
MATTER DIDN'T GIVE ###############ANY WORKING SOLUTION.
for x in alist:
inp = open("C:\\python_texts\\"+str(x)+".txt","r") #open an existing file "x.txt"
outp = open("C:\\python_texts\\"+str(x + 1)+".txt","w") #write the
result (of the below 'for') in a new file.
##############WHAT ALTERNATIVE TO ASIGN A NEW VALUE TO A LIST INSIDE THE
LOOP?
for line in inp:
alist= list(line) #from a list in the file
print alist
c = random.choice(alist) #choose an element from the list
print c
alist.remove(c) #remove it
print alist
for a in alist:
outp.write(a) #write the new list in "x+1.txt" file ######<----WHAT ALTERNATIVE TO THIS?
x = x + 1
outp.close() #close the file to be read:("C:\\python_texts\\"+str(x)+"txt","r")
inp.close() #close the file to be written :("C:\\python_texts\\"str(x + 1)+".txt","w")
--
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.