def allowed_state(self, state): ''' This method checks is a node complies with the following states: down, offline and or unknown ''' allowed_list = set( ['down', 'offline', 'unknown'] ) return bool( allowed_list.intersection( set( state ) ) )
def testUnion(self): print("Testing union!") theSet1 = set([2, 4]) theSet2 = set([1, 3, 5]) assert theSet1.union(theSet2).list == [1, 3, 5, 2, 4] theSet1 = set(["a", "b", "c"]) theSet2 = set(["d", "e", "f", "g"]) assert theSet1.union(theSet2).list == [ "d", "e", "f", "g", "a", "b", "c" ] assert theSet1.remove("c") == True assert theSet1.union(theSet2).list == ["d", "e", "f", "g", "a", "b"]
def testIntersection(self): print("Testing interseciton") theSet1 = set([1, 3, 5, 2, 4]) theSet2 = set([1, 3, 5]) assert theSet1.intersection(theSet2).list == [1, 3, 5] theSet1 = set(["a", "b", "c", "d", "e", "f", "g"]) theSet2 = set(["a", "b", "c", "d", "e", "f", "g"]) assert theSet1.intersection(theSet2).list == [ "a", "b", "c", "d", "e", "f", "g" ] assert theSet2.remove("b") == True assert theSet1.intersection(theSet2).list == [ "a", "c", "d", "e", "f", "g" ]
def toC3BDB(self, db): l = self.leftOperand.toC3BDB(db) r = self.rightOperand.toC3BDB(db) bool = self.boolean.value ls = set.set(l) rs = set.set(r) if bool == 'and': return list(ls & rs) elif bool == 'or': return list(ls | rs) elif bool == "not": return list(ls - rs) else: raise ValueError
def control(): func=raw_input('[cldog] ^_^ ') type(func) if func == ':proxy': proxy.netSet() if func == ':set': set.set() if func ==':help': help.help() if func == ':shell': shell.shell() if func == ':sql-set': sqlset.sqlSet() if func == ':sql': sql.sql() if func == ':exit': exit(0)
def testAddAndSize(self): print("Testing add and size!") testAr = [1, 3, 5, 2, 4] theSet = set(testAr) assert theSet.size == 5 theSet.add(7) assert theSet.size == 6 theSet.add(2) assert theSet.size == 6 theSet.add(8) assert theSet.size == 7
def testDifference(self): print("Testing difference!") theSet1 = set([1, 3, 5, 2, 4]) theSet2 = set([1, 3, 5]) assert theSet2.difference(theSet1).list == [2, 4] theSet1 = set(["a", "b", "c"]) theSet2 = set(["a", "b", "c", "g"]) assert theSet2.difference(theSet1).list == ["g"] theSet1 = set([1, 3, 5, 2]) theSet2 = set([1, 3, 5]) assert theSet2.difference(theSet1).list == [2] theSet1 = set(["a", "b", "c"]) theSet2 = set(["a", "b", "c", "h"]) assert theSet2.difference(theSet1).list == ["h"]
def testRemoveAndContains(self): print("Testing remove and contains") testAr = ["a", "b", "c", "d", "e", "f", "g"] theSet = set(testAr) assert theSet.size == 7 assert theSet.contains("a") == True assert theSet.remove("a") == True assert theSet.contains("a") == False assert theSet.remove("b") == True assert theSet.contains("b") == False assert theSet.remove("c") == True assert theSet.contains("c") == False assert theSet.remove("d") == True assert theSet.contains("d") == False
def testIsSubset(self): print("Testing is_subset!") theSet1 = set([1, 3, 5, 2, 4]) theSet2 = set([1, 3, 5]) assert theSet2.is_subset(theSet1) == True assert theSet1.is_subset(theSet2) == False theSet1 = set(["a", "b", "c", "d", "e", "f", "g"]) theSet2 = set(["a", "b", "c", "d", "e"]) assert theSet2.is_subset(theSet1) == True assert theSet1.is_subset(theSet2) == False theSet1 = set(["jon", "is", "the", "coolest"]) theSet2 = set(["jon", "is", "coolest"]) assert theSet2.is_subset(theSet1) == True assert theSet1.is_subset(theSet2) == False
#!/usr/bin/env python2.7 import set import get set.set() get.get()
#!/usr/bin/python import set, sys a = set.set() b = set.set() c = set.set() a.addList([1,2,3,4,5]) b.addList([6,7,8,9,10]) c.addList([3,4,5,6,7]) print 'a:' a.printd() print 'b:' b.printd() print 'c:' c.printd() test = set.set() test.printd() test.addList([1,2,3,4,5]) print 'd:' test.printd() test1 = test.pset() print 'd.pset():' test1.printd() for s in test1.getList(): s.printd() # test.addList([1,2,3,4,5])
# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # import sys from django.core.management import setup_environ from wolnelektury import settings try: set except AttributeError: from set import Set as set setup_environ(settings) from catalogue import models fragment_identifiers = set() print print 'Before: %d fragments' % models.Fragment.objects.count() print for fragment in models.Fragment.objects.all(): if (fragment.book_id, fragment.anchor) in fragment_identifiers: fragment.delete() sys.stderr.write('X') else: fragment_identifiers.add((fragment.book_id, fragment.anchor)) sys.stderr.write('.') print print 'After: %d fragments' % models.Fragment.objects.count()