[Tutor] How can I find a group of characters in a list of strings?

Jim jf_byrnes at comcast.net
Wed Jul 25 19:50:56 EDT 2018

Linux mint 18 and python 3.6

I have a list of strings that contains slightly more than a million 
items. Each item is a string of 8 capital letters like so:


I need to check and see if the letters 'OFHCMLIP' are one of the items 
in the list but there is no way to tell in what order the letters will 
appear. So I can't just search for the string 'OFHCMLIP'. I just need to 
locate any strings that are made up of those letters no matter their order.

I suppose I could loop over the list and loop over each item using a 
bunch of if statements exiting the inner loop as soon as I find a letter 
is not in the string, but there must be a better way.

I'd appreciate hearing about a better way to attack this.

thanks,  Jim

More information about the Tutor mailing list