蟒蛇是什么级别的数据类型= {S}

问题描述:

class Solution(object): 
    def removeInvalidParentheses(self, s): 
     """ 
     :type s: str 
     :rtype: List[str] 
     """ 
     def isvalid(s): 
      ctr=0 
      for string in s: 
       if string=='(': 
        ctr+=1 
       if string==')': 
        ctr-=1 
        if ctr<0: 
         return False 
      return ctr==0 
     n=len(s) 
     level={s} 
     while level: 
      valid = filter(isvalid, level) 
      if valid: 
       return valid 
      level = {s[:i] + s[i+1:] for s in level for i in range(n)} 

我想知道什么的level数据类型,因为它看起来并不像一本字典。蟒蛇是什么级别的数据类型= {S}

+0

它是一个集合的例子 – mic4ael

+2

你试过对它调用'type'吗? – user2357112

+0

为什么要问一些你可以很容易地搜索到的东西? –

它是一个set,它是一个只保存唯一对象的数据结构。

{}是一本字典。

set(){x}{x, y},{x, y, z, ...}是集合。

{x:y, ...}(即,如果它有冒号:)是词典。

+0

除非它是一个词典理解(它评估字典)。 –

+0

@ IgnacioVazquez-Abrams有冒号。 –

+0

是的,但它不是一本字典。 –