I am currently working on a little project for an escape room I'm organizing anyways I'm trying to make a python script read a txt file and store it in a List (this works) however from there I'm trying to make it look trough said list and search for a 1 and make it print the letter that is after the 1 like this where 1H1Ippo would give Hi as a result
I don't have too much knowledge from my classes on how lists work and I've tried this which made sense to me but it gives no result at all which left me clueless to what I could do. I did look on google but couldn't find any results to fix my issue or perhaps I'm just terrible at googling for this issue
with open('Wordlist.txt', 'r') as f:
words = [line.strip() for line in f]
for w in words:
if w in words == 1:
print (words[1])
CodePudding user response:
Check if the first character of w
is 1
. If it is, accumulate the second character.
result = ''
for w in words:
if w[0] == '1':
result = w[1]
print(result)
CodePudding user response:
This may be what you need
with open('Wordlist.txt', 'r') as f:
words = [line.strip() for line in f]
for index, w in enumerate(words):
if w == '1':
print(words[index 1])