Python では理解できない問題があります。文字配列内のいずれかの文字と一致する必要があるパターンがあります。そうでない場合は、問題があります。だからここに私の例があります:
pattern = "0000 006e 0022 0002 0156 00ac 0016 0016 0016 0041 0016 0041 0016 0041 0016 0016 0016 0041 0016 0041 0016 0041 0016 0041 0016 0041 0016 0041 0016 0016 0016 0016 0016 0016 0016 0016 0016 0041 0016 0016 0016 0016 0016 0041 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0041 0016 0041 0016 0016 0016 0016 0016 0016 0016 0040 05e 0105
allowedCharacters = "123456789abcdef"
したがって、私の目標は、パターンが許可された文字に準拠しているかどうかを確認することです。C# で次のことを行いましたが、Python でこれを行う方法がわかりません。
これが私の現在のコードです。
# Test that there are only valid characters in the pattern.
charPattern = list(pattern)
expression = list("01234567890abcdef")
for currentChar in pattern:
if len(charPattern) - pattern[-1::-1].index("0123456789abcdef") - 1:
self.assertTrue(False, logger.failed("The invalid character: " + currentChar + " was found in the IRCode pattern for: " + ircode))`enter code here`
アイデア/提案/コード例は大歓迎です。
ありがとう。