-2

I have to find 6 distincts words in a bunch of lists. For example in first list, there will be word 'me', in second word 'us'.

I've already found the line number using this code:

def creatList(file):
try:
    for i,line in enumerate(file,1):

and pass found values to another function,

line=(line.rstrip()).split()
rawList=[]

rawList.append(line)

creatRuleFile(i,rawList)

inside that function,

def creatRuleFile(p,new):
   print(new)
   print("{0}. {1}".format(p, new))
   lookup ='me'
   if p==1:
      print('found at line:', lookup)

my code is not working as I want... appreciate if you can suggest an answer. Thank you.

LookAheadAtYourTypes
  • 1,629
  • 2
  • 20
  • 35

1 Answers1

0

Has been answered before: Python: Find in list

use something like

stuff_I_want_to_find = "whatever"
if stuff_I_want_to_find in myList:
    index = myList.find(stuff_I_want_to_find)

now you have to iterate over your lists and over your words, which will essentially be two loops.

Community
  • 1
  • 1
Mohammed Li
  • 823
  • 2
  • 7
  • 22