
我在做First Unique Character in a String - LeetCode的时候,碰到“SyntaxError: Generator expression must be parenthesized”。
我想知道的是,多个参数时,为什么 Generator expression must be parenthesized ?
# 重现代码 class Solution: def firstUniqChar(self, s: str) -> int: char_to_index = {} for i, c in enumerate(s): if c in char_to_index: char_to_index[c] = -1 else: char_to_index[c] = i return min( index for index in char_to_index.values() if index != -1, default=-1 ) 1 jfcherng 2023-01-07 14:32:58 +08:00 |