How to iterate through every word several times in python?
up vote
0
down vote
favorite
I'm making a script that should take in a set of words in a file, encrypt them in 25 different ways, then output the results to another file.
So what i have so far is a script that takes in all the words, encrypt them only once and outputs the list. I can't figure out how to encrypt each word 25 times (meaning, making 25 new words out of each word)
Here is my code so far:
for c in range(len(text)):
lister = text[c]
s += 1
print("Cipher number %s: " % c + encrypt(lister, s))
output_file.write("n")
output_file.write(encrypt(lister, s))
text is the file containing the words, and the function encrypt takes in that list, and s is the number of shifts for the encryption, meaning s = 1 is one encryption way, and s = 2 is another way to encrypt the same word. The code right now encrypts all the words in different encryptions since s changes its value each time the for loop goes through a new word
How can i make the for loop change the value of s only after it has encrypted the previous word 25 times at s = 1 to s = 25?
python
add a comment |
up vote
0
down vote
favorite
I'm making a script that should take in a set of words in a file, encrypt them in 25 different ways, then output the results to another file.
So what i have so far is a script that takes in all the words, encrypt them only once and outputs the list. I can't figure out how to encrypt each word 25 times (meaning, making 25 new words out of each word)
Here is my code so far:
for c in range(len(text)):
lister = text[c]
s += 1
print("Cipher number %s: " % c + encrypt(lister, s))
output_file.write("n")
output_file.write(encrypt(lister, s))
text is the file containing the words, and the function encrypt takes in that list, and s is the number of shifts for the encryption, meaning s = 1 is one encryption way, and s = 2 is another way to encrypt the same word. The code right now encrypts all the words in different encryptions since s changes its value each time the for loop goes through a new word
How can i make the for loop change the value of s only after it has encrypted the previous word 25 times at s = 1 to s = 25?
python
As far as I understand, 's' is adding either the digit 1 to the text or the digit 1 refers to some cipher which has the key 1? Is that correct? If so, can you increment 's' and run 's' until the incrementation reaches 25?
– Alex_P
Nov 10 at 19:30
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm making a script that should take in a set of words in a file, encrypt them in 25 different ways, then output the results to another file.
So what i have so far is a script that takes in all the words, encrypt them only once and outputs the list. I can't figure out how to encrypt each word 25 times (meaning, making 25 new words out of each word)
Here is my code so far:
for c in range(len(text)):
lister = text[c]
s += 1
print("Cipher number %s: " % c + encrypt(lister, s))
output_file.write("n")
output_file.write(encrypt(lister, s))
text is the file containing the words, and the function encrypt takes in that list, and s is the number of shifts for the encryption, meaning s = 1 is one encryption way, and s = 2 is another way to encrypt the same word. The code right now encrypts all the words in different encryptions since s changes its value each time the for loop goes through a new word
How can i make the for loop change the value of s only after it has encrypted the previous word 25 times at s = 1 to s = 25?
python
I'm making a script that should take in a set of words in a file, encrypt them in 25 different ways, then output the results to another file.
So what i have so far is a script that takes in all the words, encrypt them only once and outputs the list. I can't figure out how to encrypt each word 25 times (meaning, making 25 new words out of each word)
Here is my code so far:
for c in range(len(text)):
lister = text[c]
s += 1
print("Cipher number %s: " % c + encrypt(lister, s))
output_file.write("n")
output_file.write(encrypt(lister, s))
text is the file containing the words, and the function encrypt takes in that list, and s is the number of shifts for the encryption, meaning s = 1 is one encryption way, and s = 2 is another way to encrypt the same word. The code right now encrypts all the words in different encryptions since s changes its value each time the for loop goes through a new word
How can i make the for loop change the value of s only after it has encrypted the previous word 25 times at s = 1 to s = 25?
python
python
asked Nov 10 at 19:19
MonaS
1
1
As far as I understand, 's' is adding either the digit 1 to the text or the digit 1 refers to some cipher which has the key 1? Is that correct? If so, can you increment 's' and run 's' until the incrementation reaches 25?
– Alex_P
Nov 10 at 19:30
add a comment |
As far as I understand, 's' is adding either the digit 1 to the text or the digit 1 refers to some cipher which has the key 1? Is that correct? If so, can you increment 's' and run 's' until the incrementation reaches 25?
– Alex_P
Nov 10 at 19:30
As far as I understand, 's' is adding either the digit 1 to the text or the digit 1 refers to some cipher which has the key 1? Is that correct? If so, can you increment 's' and run 's' until the incrementation reaches 25?
– Alex_P
Nov 10 at 19:30
As far as I understand, 's' is adding either the digit 1 to the text or the digit 1 refers to some cipher which has the key 1? Is that correct? If so, can you increment 's' and run 's' until the incrementation reaches 25?
– Alex_P
Nov 10 at 19:30
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
What you are looking for is a nested loop. Simply put, you need to do a task 25 times for each word.
for c in range(len(text)):
lister = text[c]
for s in range(1, 26): #goes from 1 to 25.
print("Cipher number %s: " % c + encrypt(lister, s))
output_file.write("n")
output_file.write(encrypt(lister, s))
I should also mention that python gives us a much nicer way of iterating through lists using the "in" operator.
for lister in text:
for s in range(1, 26): #goes from 1 to 25.
print("Cipher set for word ",lister)
output_file.write("n")
output_file.write(encrypt(lister, s))
If you need both index numbers while iterating through a list, use enumerate instead.
You're the man. That's exactly what i was looking for. thank you.
– MonaS
Nov 10 at 20:07
add a comment |
up vote
0
down vote
I would use a nested loop, inside the current loop you have. Make that loop run 25 times for each time the outer loop iterates, and increase the value of s
each time the inner loop iterates.
In other words, put the main body of your current loop inside for s in range(25):
. That, in turn, should go inside for c in range(len(text)):
. Does this help?
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
What you are looking for is a nested loop. Simply put, you need to do a task 25 times for each word.
for c in range(len(text)):
lister = text[c]
for s in range(1, 26): #goes from 1 to 25.
print("Cipher number %s: " % c + encrypt(lister, s))
output_file.write("n")
output_file.write(encrypt(lister, s))
I should also mention that python gives us a much nicer way of iterating through lists using the "in" operator.
for lister in text:
for s in range(1, 26): #goes from 1 to 25.
print("Cipher set for word ",lister)
output_file.write("n")
output_file.write(encrypt(lister, s))
If you need both index numbers while iterating through a list, use enumerate instead.
You're the man. That's exactly what i was looking for. thank you.
– MonaS
Nov 10 at 20:07
add a comment |
up vote
1
down vote
What you are looking for is a nested loop. Simply put, you need to do a task 25 times for each word.
for c in range(len(text)):
lister = text[c]
for s in range(1, 26): #goes from 1 to 25.
print("Cipher number %s: " % c + encrypt(lister, s))
output_file.write("n")
output_file.write(encrypt(lister, s))
I should also mention that python gives us a much nicer way of iterating through lists using the "in" operator.
for lister in text:
for s in range(1, 26): #goes from 1 to 25.
print("Cipher set for word ",lister)
output_file.write("n")
output_file.write(encrypt(lister, s))
If you need both index numbers while iterating through a list, use enumerate instead.
You're the man. That's exactly what i was looking for. thank you.
– MonaS
Nov 10 at 20:07
add a comment |
up vote
1
down vote
up vote
1
down vote
What you are looking for is a nested loop. Simply put, you need to do a task 25 times for each word.
for c in range(len(text)):
lister = text[c]
for s in range(1, 26): #goes from 1 to 25.
print("Cipher number %s: " % c + encrypt(lister, s))
output_file.write("n")
output_file.write(encrypt(lister, s))
I should also mention that python gives us a much nicer way of iterating through lists using the "in" operator.
for lister in text:
for s in range(1, 26): #goes from 1 to 25.
print("Cipher set for word ",lister)
output_file.write("n")
output_file.write(encrypt(lister, s))
If you need both index numbers while iterating through a list, use enumerate instead.
What you are looking for is a nested loop. Simply put, you need to do a task 25 times for each word.
for c in range(len(text)):
lister = text[c]
for s in range(1, 26): #goes from 1 to 25.
print("Cipher number %s: " % c + encrypt(lister, s))
output_file.write("n")
output_file.write(encrypt(lister, s))
I should also mention that python gives us a much nicer way of iterating through lists using the "in" operator.
for lister in text:
for s in range(1, 26): #goes from 1 to 25.
print("Cipher set for word ",lister)
output_file.write("n")
output_file.write(encrypt(lister, s))
If you need both index numbers while iterating through a list, use enumerate instead.
answered Nov 10 at 19:29
Paritosh Singh
2116
2116
You're the man. That's exactly what i was looking for. thank you.
– MonaS
Nov 10 at 20:07
add a comment |
You're the man. That's exactly what i was looking for. thank you.
– MonaS
Nov 10 at 20:07
You're the man. That's exactly what i was looking for. thank you.
– MonaS
Nov 10 at 20:07
You're the man. That's exactly what i was looking for. thank you.
– MonaS
Nov 10 at 20:07
add a comment |
up vote
0
down vote
I would use a nested loop, inside the current loop you have. Make that loop run 25 times for each time the outer loop iterates, and increase the value of s
each time the inner loop iterates.
In other words, put the main body of your current loop inside for s in range(25):
. That, in turn, should go inside for c in range(len(text)):
. Does this help?
add a comment |
up vote
0
down vote
I would use a nested loop, inside the current loop you have. Make that loop run 25 times for each time the outer loop iterates, and increase the value of s
each time the inner loop iterates.
In other words, put the main body of your current loop inside for s in range(25):
. That, in turn, should go inside for c in range(len(text)):
. Does this help?
add a comment |
up vote
0
down vote
up vote
0
down vote
I would use a nested loop, inside the current loop you have. Make that loop run 25 times for each time the outer loop iterates, and increase the value of s
each time the inner loop iterates.
In other words, put the main body of your current loop inside for s in range(25):
. That, in turn, should go inside for c in range(len(text)):
. Does this help?
I would use a nested loop, inside the current loop you have. Make that loop run 25 times for each time the outer loop iterates, and increase the value of s
each time the inner loop iterates.
In other words, put the main body of your current loop inside for s in range(25):
. That, in turn, should go inside for c in range(len(text)):
. Does this help?
answered Nov 10 at 19:29
Calc-You-Later
1
1
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242569%2fhow-to-iterate-through-every-word-several-times-in-python%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
As far as I understand, 's' is adding either the digit 1 to the text or the digit 1 refers to some cipher which has the key 1? Is that correct? If so, can you increment 's' and run 's' until the incrementation reaches 25?
– Alex_P
Nov 10 at 19:30