python什么是level = {s}的数据类型

时间:2017-08-03 21:38:56

标签: python data-structures

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的数据类型是什么,因为它看起来不像字典。

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

set()是一本字典。

{x}{x, y}{x, y, z, ...}{x:y, ...}是设置。

:(即如果它有冒号var buttonArray: [UIButton] = [] var checkBoxArray: [UIView] = [] var labelArray: [UILabel] = [] struct ObjectDefinition { let classType: UIView.Type let frame: CGRect } func createAllTheStuff() { let objectDefinitions: [ObjectDefinition] = [ ObjectDefinition(classType: UIButton.self, frame: CGRect(x: 0, y: 0, width: 100, height: 200)), ObjectDefinition(classType: UIButton.self, frame: CGRect(x: 10, y: 10, width: 10, height: 25)), ObjectDefinition(classType: UIView.self, frame: CGRect(x: 0, y: 0, width: 50, height: 210)), ObjectDefinition(classType: UILabel.self, frame: CGRect(x: 0, y: 0, width: 1200, height: 20)) ] for objectDefinition in objectDefinitions { initializeStuff(objectType: objectDefinition.classType, frame: objectDefinition.frame) } } func initializeStuff(objectType: UIView.self, frame: CGRect) { switch objectType { case UIButton.self: let button = UIButton(frame: frame) buttonArray.append(button) case UILabel.self: let label = UILabel(frame: frame) labelArray.append(label) case UIView.self: let checkBox = UIView(frame: frame) checkBoxArray.append(checkBox) } } )是字典。