Python | Set Membership Pattern
see the Successfully Accepted Submission\n\n# Code\npython3 []\nclass Solution:\n    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n 
[see the Successfully Accepted Submission](https://leetcode.com/problems/count-the-number-of-consistent-strings/submissions/1387134061/?envType=daily-question&envId=2024-09-12)\n\n# Code\n```python3 []\nclass Solution:\n    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n        allowed_set = set(allowed)  # Convert allowed string to a set for O(1) lookups\n        consistent_count = 0\n        \n        for word in words:\n            if all(char in allowed_set for char in word):\n                consistent_count += 1\n        \n        return consistent_count\n\n```\n### Explanation:\n\n1. `allowed_set = set(allowed)`: Convert the `allowed` string into a set of characters for faster lookup.\n\n2. `for word in words`: Iterate over each word in the `words` list.\n\n3. `if all(char in allowed_set for char in word)`: For each word, check if every character is present in `allowed_set`. If this is true for all characters, the word is consistent.\n\n4. `consistent_count += 1`: If the word is consistent, increase the count.\n\n5. `return consistent_count`: After iterating through all the words, return the count of consistent strings.\n\n### Time Complexity:\n\n- Converting `allowed` to a set takes **O(n)**, where `n` is the length of the `allowed` string.\n- For each word, checking if all characters are in the set takes **O(m)**, where `m` is the length of the word. \n- Since we do this for each word in the `words` list, the total time complexity is **O(n + m * k)**, where `n` is the length of `allowed`, `m` is the average length of words, and `k` is the number of words.\n\n\n![image](https://assets.leetcode.com/users/images/b1e4af48-4da1-486c-bc97-b11ae02febd0_1696186577.992237.jpeg)\n
['Python3']