Ejemplo n.º 1
0
 def testRemoveDups(self):
     testList = List.LinkedList()
     for v in range(10):
         testList.append(v)
     # should not remove anything
     removed = removeDuplicates(testList)
     for i, e in enumerate(removed):
         self.assertEqual(i, e)
     # 10 elements
     self.assertEqual([i for i, e in enumerate(removed)],
                      [i for i in range(10)])
     # add same elements again
     for v in range(10):
         testList.append(v)
     removed2 = removeDuplicates(testList)
     self.assertEqual([v for v in removed], [v for v in removed2])
     # create another list
     testList2 = List.LinkedList()
     for i in range(10):
         testList2.append(0)
     removed = removeDuplicates(testList2)
     # should only contain one element of 0
     self.assertEqual(removed.get(0).value, 0)
     self.assertRaises(IndexError, removed.get, 1)
     # empty case
     for val in removeDuplicates(List.LinkedList()):
         self.fail("Cannot enter here")
Ejemplo n.º 2
0
    def __init__(self, iterable=[], nrow=1, ncol=1, storage='rows'):

        self.data = List(max_length=nrow * ncol)
        self.storage = storage
        self.shape = (nrow, ncol)

        if len(iterable) > 0:
            if isinstance(iterable[0], (int, float)):
                if len(iterable) != ncol * nrow:
                    raise ValueError(
                        'the size of the initial values does not match array dimensions'
                    )

                for i in range(nrow * ncol):
                    if not isinstance(iterable[i], (int, float)):
                        raise ValueError('initial value must be numeric')
                    self.data.append(iterable[i])

            elif isinstance(iterable[0], (list, tuple, List)):
                nrow, ncol = len(iterable), len(iterable[0])
                self.shape = (nrow, ncol)
                self.data = List(max_length=nrow * ncol)
                for i in range(nrow):
                    for j in range(ncol):
                        self.data.append(iterable[i][j])
        else:
            for i in range(nrow * ncol):
                self.data.append(0)
Ejemplo n.º 3
0
def map5(lst):
    return \
        pipe(lst,
        [
            F(List.map5)(
                lambda a, b, c, d, e:
                    F(Tuple.pair)(
                        a,
                        F(Tuple.pair)(
                            b,
                            F(Tuple.pair)(
                                c,
                                F(Tuple.pair)(
                                    d,
                                    e
                                )
                            )
                        )
                    )
                ,
                List.toElm([ 10, 20, 30 ]),
                List.toElm([ 5, 8, 7 ]),
                List.toElm([ 1, 2, 3, 4, 5 ]),
                List.toElm([ 33, 97, 103 ])
            )
        ])
Ejemplo n.º 4
0
    def __init__(self,
                 parent_widget,
                 resource,
                 response=None,
                 messageBar=None,
                 parent_object=None):
        Frame.__init__(self, parent_widget)
        self.parent_widget = parent_widget
        self.parent_object = parent_object
        self.response = response
        self.resource = resource
        self.mb = messageBar
        self.opts = Options.program_options  # Global alias

        self.locations = List.List()
        self.navList = List.List()

        self._createPopup()

        self.currentContent = None

        # Go wherever the user intended us to go.
        self.goElsewhere(resource)

        return None
Ejemplo n.º 5
0
def permuteFloats(lst):
    startList = \
        pipe(lst,
        [
            F(List.map)(
                Basics.toFloat
            )
        ])


    newElements = \
        pipe(startList,
        [
            List.sort,
            F(List.map)(
                lambda n:
                    (n + 0.5)

            ),
            lambda items:
                List.cons(0.5, items)

        ])

    return pipe(newElements, [
        F(List.map)(List.singleton),
        F(List.map)(lambda x: List.append(startList, x))
    ])
Ejemplo n.º 6
0
def testSetStuff():
    dct1 = Dict.fromList(List.toElm([
        (1, 10),
        (2, 20),
        (3, 30),
    ]))

    dct2 = Dict.fromList(List.toElm([
        (3, 300),
        (4, 400),
        (5, 500),
    ]))

    print('union')
    assert list(Dict.keys(Dict.union(dct1, dct2))) == [1,2,3,4,5]

    print('intersect')
    assert list(Dict.keys(Dict.intersect(dct1, dct2))) == [3]

    print('diff')
    assert list(Dict.keys(Dict.diff(dct1, dct2))) == [1,2]

    print('merge')
    outList = Dict.merge(
        lambda k, v, lst: List.cons((k, v), lst),
        lambda k, v1, v2, lst: List.cons((k, v1, v2), lst),
        lambda k, v, lst: List.cons((v, k), lst),
        dct1,
        dct2,
        List.empty)
    assert list(outList) == [ (500, 5), (400, 4), (3, 30, 300), (2, 20), (1, 10) ]
Ejemplo n.º 7
0
def print_list(root):
    # dirs 文件夹
    # files 文件
    for root, dirs, files in os.walk(root):
        for each in dirs:
            # 匹配每个文件夹
            match = Key.match_pattern(each)
            if match:
                List.step_in(root, each)
                print(get_alias(os.getcwd()))
                os.chdir(root)
Ejemplo n.º 8
0
def map3(lst):
    return \
        pipe(lst,
        [
            F(List.map3)(
                lambda x, y, z:
                    ((x * 100) + ((y * 10) + z))
                ,
                List.toElm([ 10, 20, 30 ]),
                List.toElm([ 5, 8, 7 ])
            )
        ])
Ejemplo n.º 9
0
 def test_merge(self):
     first, second = random_list(), random_list()
     test_struct_first, test_struct_second = List.DoublyLinkedList(
     ), List.DoublyLinkedList()
     for elem in first:
         test_struct_first.add_back(elem)
     for elem in second:
         test_struct_second.add_back(elem)
     index = random.randint(0, len(first) - 1)
     first = first[:index] + second + first[index:]
     test_struct_first.merge(test_struct_second, index)
     self.assertTrue(content_equal(first, test_struct_first))
Ejemplo n.º 10
0
def map4(lst):
    return \
        pipe(lst,
        [
            F(List.map4)(
                lambda a, b, c, d:
                    ((a + b) * (c + d))
                ,
                List.toElm([ 10, 20, 30 ]),
                List.toElm([ 5, 8, 7 ]),
                List.toElm([ 1, 2 ])
            )
        ])
Ejemplo n.º 11
0
def NearestNeighbour(locations):
    start_time = time.time()
    shortDistance = 100000
    path = []
    counter = 0
    for x in locations:
        counter += 1
        if counter % 10 == 0:
            print("%.2f%% complete" % (counter / len(locations) * 100),
                  end='\r')
        tempPath = []
        tempLocations = copy.deepcopy(locations)
        currentLocation = x
        tempLocations.remove(currentLocation)
        tempPath.append(x)
        totalDistance = 0

        while tempLocations:
            tempNearestNeighbour = currentLocation
            tempShortestDistance = 10000

            for x in tempLocations:
                if ListFunctions.Distance(
                        x, currentLocation
                ) < tempShortestDistance and ListFunctions.Distance(
                        x, currentLocation) != 0:
                    tempShortestDistance = ListFunctions.Distance(
                        x, currentLocation)
                    tempNearestNeighbour = x
            currentLocation = tempNearestNeighbour
            tempLocations.remove(currentLocation)
            tempPath.append(currentLocation)
            totalDistance += tempShortestDistance

            if len(tempLocations) == 0:
                tempPath.append(tempPath[0])
                totalDistance += ListFunctions.Distance(
                    tempPath[len(tempPath) - 1], tempPath[len(tempPath) - 2])

        if totalDistance < shortDistance:
            shortDistance = totalDistance
            path = tempPath

    print("the total distance is ", shortDistance, " path is ", path)
    print("This process took %.4f seconds to complete" %
          int(time.time() - start_time))

    V.DisplayRoute(path)
Ejemplo n.º 12
0
def all_(f, t):
    """
    all :: Foldable t => (a -> bool) -> t a -> bool

    Determines whether all elements of the structure satisfy the predicate.
    """
    return DL.all_(toList(t))
Ejemplo n.º 13
0
def any_(f, t):
    """
    any :: Foldable t => (a -> bool) -> t a -> bool

    Determines whether any element of the structure satisfies the predicate.
    """
    return DL.any_(toList(t))
Ejemplo n.º 14
0
def concat(t):
    """
    concat :: Foldable t => t [a] -> [a]

    The concatenation of all the elements of a container of lists.
    """
    return DL.concat(toList(t))
Ejemplo n.º 15
0
def add_two_line(self,from_who,msg_to_add):
    self.ml.add_widget(List.TwoLineListItem(text=msg_to_add,
        secondary_text=from_who,
        markup=True,
        text_size=(self.width,None),
        size_hint_y=None,
        font_size=(self.height / 23)))
Ejemplo n.º 16
0
    def __init__(self, *args):
        Toplevel.__init__(self, *args)

        self.title("Search")

        self.frame = Frame(self, padx=2, pady=2, bd=3)
        self.frame.pack()

        # Using Tk 's variable tracing
        # Checkout http://stupidpythonideas.blogspot.in/2013/12/tkinter-validation.html
        self.namevar = StringVar()
        self.namevar.trace('w', self.onUpdate)
        search = ttk.Entry(self.frame, textvariable=self.namevar)
        search.grid(row=0, columnspan=2)
        search.focus_set()
        # Binding a <Return> pressed event
        search.bind('<Return>', lambda _:  self.self.onUpdate())

        s = ttk.Style()
        s.configure("Submit.TButton", font=BUTTON_FONT, sticky="e")

        searchBtn = ttk.Button(self.frame, text="Search",
                               style="Submit.TButton",
                               command=lambda:  self.onUpdate()
                               )
        searchBtn.grid(row=0, column=3, sticky="e")
        # Awesomeness here
        self.tree = List.getTreeFrame(self, bd=3)
        self.tree.pack()
Ejemplo n.º 17
0
 def test_iteration(self):
     test_struct = List.SinglyLinkedList(random_list())
     counter = 0
     for x in test_struct:
         self.assertEqual(x, test_struct[counter])
         counter += 1
     self.assertEqual(counter, len(test_struct))
Ejemplo n.º 18
0
    def addConfigBtn(self, login):
        # configured buttons
        # btnList = (addBtn, listBtn, getBtn)

        # Creating temp references to images using temp1,2,3 so as to disallow
        # garbage collection problems
        btnList = ["Add", "List", "Search"]
        btnCmdList = [
            lambda: Add.AddWindow(self), lambda: List.ListWindow(self),
            lambda: Search.SearchWindow(self)
        ]
        f = []  # Frames array
        img = []  # image array
        self.temp = []  # temp array

        for i in xrange(3):
            f.append(Frame(login, padx=2, width=50, height=50))
            f[i].grid(row=3, column=i)
            img.append(
                PhotoImage(file=btnList[i] + ".gif", width=48, height=48))
            self.temp.append(img[i])
            ttk.Button(f[i],
                       image=img[i],
                       text=btnList[i],
                       compound="top",
                       style="Submit.TButton",
                       command=btnCmdList[i]).grid(sticky="NWSE")
Ejemplo n.º 19
0
    def __init__(self, *args):
        Toplevel.__init__(self, *args)

        self.title("Search")

        self.frame = Frame(self, padx=2, pady=2, bd=3)
        self.frame.pack()

        # Using Tk 's variable tracing
        # Checkout http://stupidpythonideas.blogspot.in/2013/12/tkinter-validation.html
        self.namevar = StringVar()
        self.namevar.trace('w', self.on_update)
        search = ttk.Entry(self.frame, textvariable=self.namevar)
        search.grid(row=0, columnspan=2, padx=3)
        search.focus_set()
        # Binding a <Return> pressed event
        search.bind('<Return>', lambda _: self.on_update())

        s = ttk.Style()
        s.configure("Submit.TButton", font=BUTTON_FONT, sticky="e")

        search_button = ttk.Button(self.frame,
                                   text="Search",
                                   style="Submit.TButton",
                                   command=lambda: self.on_update())
        search_button.grid(row=0, column=3, padx=3, sticky="e")
        # Awesomeness here
        self.tree = List.GetTreeFrame(self, bd=3)
        self.tree.pack()
Ejemplo n.º 20
0
def BruteForce(locations):
    start_time = time.time()
    # Gets all the path combinations
    p = permutations(locations)
    p = list(p)
    smallestIndex = 0
    smallestDistance = 999999

    counter = 0
    # Go through all the paths
    for x in p:
        x = list(x)
        x.append(x[0])
        if counter % 1000 == 0:
            print("%.2f%% complete" % (counter / len(p) * 100), end='\r')
        # gets the path distance
        tempDistance = ListFunctions.TotalDistance(x)
        # if this path is shorter than previous best, remember this
        if smallestDistance > tempDistance:
            smallestDistance = tempDistance
            smallestIndex = counter
        counter += 1

    path = []
    for x in p[smallestIndex]:
        path.append(x)
    path.append(p[smallestIndex][0])

    # prints smallest distance found
    print(path, " is the path, the distance is ", smallestDistance)
    print("This process took %.4f seconds to complete" %
          int(time.time() - start_time))

    V.DisplayRoute(path)
Ejemplo n.º 21
0
def App(locations):
    os.system('cls||clear')
    print("Welcome to the TSP calculator\n")
    temp = ""
    while temp != "Q":
        os.system('cls||clear')
        choice = False
        print("Input a number and press Enter to perform an action\n")
        print("1 - Calculate shortest path")
        print("2 - Update locations list")
        print("3 - View locations list")
        print("Q - Quit")

        temp = input()
        os.system('cls||clear')
        if temp == "1":
            Run(locations)
            choice = True

        if temp == "2":
            locations = UpdateLocations(locations)
            choice = True

        if temp == "3":
            ListFunctions.ViewList(locations)
            V.ShowPositions(locations)
            choice = True

        if temp == "Q" or temp == "q":
            print("Goodbye!")
            return

        if choice == False:
            print("Command not recognised, enter a number between 1 and 3\n")
Ejemplo n.º 22
0
def fromList(assocs):
    def _anon1(*args):
        (key, value), dict = args

        return insert(key, value, dict)

    return List.foldl(_anon1, empty, assocs)
Ejemplo n.º 23
0
def add_list():
	if request.method == "POST":
		title = request.form["title"]
		description = request.form["about"]
		items = request.form['items']
		new_list = List(title, description, 0)
		new_items = List_Item(items)
		list_created = False
		items_created = False
		new_items.content
		new_list.items.append(new_items)
		if new_list.title and new_list.description:
			db_session.add(new_list)
			list_created = True
		else:
			flash("your list must have a title and a desciption")
		if new_items.content:
			list_items = True
			db_session.add(new_items)
		else:
			flash("your list must have some items")
		if list_created and items_created:
			try:
				db_session.commit()
			except Exception as e:
				print(e)
				db_session.rollback()
				db_session.flush()
		created_list = db_session.query(List).filter(List.title == title).first()
		redirect_id = created_list.id
		redirect_title = created_list.title
		return redirect(url_for('routes.list', title=redirect_title, id=redirect_id))
	return render_template('add_list.html')
Ejemplo n.º 24
0
    def diag(self):
        l = List()
        n = min(self.shape)
        for i in range(n):
            l.append(self.data[i][i])

        return l
Ejemplo n.º 25
0
def all_(f, t):
    """
    all :: Foldable t => (a -> bool) -> t a -> bool

    Determines whether all elements of the structure satisfy the predicate.
    """
    return DL.all_(toList(t))
Ejemplo n.º 26
0
def any_(f, t):
    """
    any :: Foldable t => (a -> bool) -> t a -> bool

    Determines whether any element of the structure satisfies the predicate.
    """
    return DL.any_(toList(t))
Ejemplo n.º 27
0
def concat(t):
    """
    concat :: Foldable t => t [a] -> [a]

    The concatenation of all the elements of a container of lists.
    """
    return DL.concat(toList(t))
Ejemplo n.º 28
0
def concatMap(f, t):
    """
    concatMap :: Foldable t => (a -> [b]) -> t a -> [b]

    Map a function over all the elements of a container and concatenate the
    resulting lists.
    """
    return DL.concatMap(f, toList(t))
Ejemplo n.º 29
0
def removeDuplicates(input_list):
    newList = List.LinkedList()
    val_set = set()
    for val in input_list:
        if val not in val_set:
            val_set.add(val)
            newList.append(val)
    return newList
Ejemplo n.º 30
0
def minimumBy_(f, t):
    """
    minimumBy :: Foldable t => (a -> a -> Ordering) -> t a -> a

    The least element of a non-empty structure with respect to the given
    comparison function.
    """
    return DL.minimumBy(toList(t))
Ejemplo n.º 31
0
def concatMap(f, t):
    """
    concatMap :: Foldable t => (a -> [b]) -> t a -> [b]

    Map a function over all the elements of a container and concatenate the
    resulting lists.
    """
    return DL.concatMap(f, toList(t))
Ejemplo n.º 32
0
 def test_add_first(self):
     test_struct = List.SinglyLinkedList()
     test_data = []
     # print()
     for i in random_list():
         test_data.insert(0, i)
         test_struct.add_front(i)
     self.assertTrue(content_equal(test_data, test_struct))
Ejemplo n.º 33
0
def lbp(op):
    L_list = List.loop_list()
    L_list.initlist(op)
    Min = L_list.traverse(0)
    for i in range(1, 8):
        if(L_list.traverse(i) < Min):
            Min = L_list.traverse(i)
    return Min
Ejemplo n.º 34
0
def minimumBy_(f, t):
    """
    minimumBy :: Foldable t => (a -> a -> Ordering) -> t a -> a

    The least element of a non-empty structure with respect to the given
    comparison function.
    """
    return DL.minimumBy(toList(t))
Ejemplo n.º 35
0
def and_(t):
    """
    and :: Foldable t => t bool -> bool

    and returns the conjunction of a container of Bools. For the result to be
    True, the container must be finite; False, however, results from a False
    value finitely far from the left end.
    """
    return DL.and_(toList(t))
Ejemplo n.º 36
0
def __main__():
    check_files_and_folders()
    socket = Socket.ServerSocket()
    connection = socket.Socket()
    sr = Server(connection, Cryptography.session_crypto(None), Registery.Registery(), Login.serverLogin(),
                Download.Download(), Upload.Upload(), List.List(), Read.Read(), Write.Write(),
                SessionKeyExchange.ServerSession(None),
                DACCommands.DACCommands(), Auditor.Auditor())
    sr.Handler()
Ejemplo n.º 37
0
def or_(t):
    """
    or :: Foldable t => t bool -> bool

    or returns the disjunction of a container of Bools. For the result to be
    False, the container must be finite; True, however, results from a True
    value finitely far from the left end.
    """
    return DL.or_(toList(t))
Ejemplo n.º 38
0
def foldr(lst):
    return \
        pipe(lst,
        [
            F(List.foldr)(
                List.cons,
                List.toElm([  ])
            )
        ])
Ejemplo n.º 39
0
def map2(lst):
    return \
        pipe(lst,
        [
            F(List.map2)(
                List.range,
                List.toElm([ 1, 2, 3 ])
            )
        ])
Ejemplo n.º 40
0
def find(f, t):
    """
    find :: Foldable t => (a -> bool) -> t a -> Maybe a

    The find function takes a predicate and a structure and returns the
    leftmost element of the structure matching the predicate, or Nothing if
    there is no such element.
    """
    return DL.find(f, toList(t))
Ejemplo n.º 41
0
def process_input(command):
	if command == 'exit':
		printing_functions.greet_user()

	elif command == 'help':
		printing_functions.print_list_of_commands()

	elif command == 'show_lists':
		archive = "archive.txt"
		printing_functions.print_file_content(archive)

	elif command.startswith('show_list '):
		list_name = List.get_list_name_from_command(command)
		printing_functions.print_file_content(list_name)

	elif command.startswith('add '):
		list_name = List.get_list_name_from_command(command)
		new_person = add_person()
		List.add_person_to_list_file(new_person, list_name)

	elif command.startswith('create '):
		list_name = List.get_arguments(command, 1)
		new_list = List.List(list_name)

	elif command.startswith('search_email'):
		email = List.get_arguments(command, 1)
		active_mailing_lists = List.find_email(email)
		printing_functions.print_elements_of_list(active_mailing_lists)

	elif command.startswith('merge_lists'):
		arguments = List.get_arguments(command, 3)
		first_list, second_list, name_new_list = arguments[0], arguments[1], arguments[2]
		List.merge_lists(first_list, second_list, name_new_list)

	elif command.startswith('export'):
		list_index = List.get_arguments(command, 1)
		List.export(list_index)
		
	else:
		printing_functions.bad_input_warning()
Ejemplo n.º 42
0
def init():
  Ur.init()
  AbInitio.init()
  Particle.init()
  AttributeGroup.init()
  GroupInit()
  FSM.init()
  lfInit()
  Element.init()
  Component.init()
  List.init()
  elts.Init.init()
  validate.veInit()
  # Could this be computed from the reflectedName property of the types -- does
  # Python give access to the class hierarchy top-down?
  psviIndMap.update({'schema':DumpedSchema,
            'atomic':(SimpleType,AbInitio.AbInitio),
            'list':(SimpleType,List.List),
            'union':(SimpleType,Union),
            'complexTypeDefinition':ComplexType,
            'attributeUse':AttributeUse,
            'attributeDeclaration':Attribute,
            'particle':Particle.Particle,
            'modelGroupDefinition':(Group,ModelGroup),
            'modelGroup':Group,
            'elementDeclaration':Element.Element,
            'wildcard':Wildcard,
            'annotation':None,
            'enumeration':Enumeration,
            'whiteSpace':Whitespace,
            'pattern':Pattern,
            'maxInclusive':MaxInclusive,
            'minInclusive':MinInclusive,
            'fractionDigits':FractionDigits,
            'precision':Precision,
            'lexicalMappings':LexicalMappings,
            'attributeGroupDefinition':AttributeGroup.AttributeGroup,
            'key':Key,
            'keyref':Keyref,
            'unique':Unique,
            'xpath':xpathTemp})
  auxComponentMap.update({'namespaceSchemaInformation':namespaceSchemaInformation,
                          'valueConstraint':valueConstraint,
                          'namespaceConstraint':namespaceConstraint,
                          'contentType':contentType,
                          'schemaDocument':schemaDocument})
  _Nmtoken=("1.0",u'[-.:A-Z_a-z\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u0131\u0134-\u013e\u0141-\u0148\u014a-\u017e\u0180-\u01c3\u01cd-\u01f0\u01f4-\u01f5\u01fa-\u0217\u0250-\u02a8\u02bb-\u02c1\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03ce\u03d0-\u03d6\u03da\u03dc\u03de\u03e0\u03e2-\u03f3\u0401-\u040c\u040e-\u044f\u0451-\u045c\u045e-\u0481\u0490-\u04c4\u04c7-\u04c8\u04cb-\u04cc\u04d0-\u04eb\u04ee-\u04f5\u04f8-\u04f9\u0531-\u0556\u0559\u0561-\u0586\u05d0-\u05ea\u05f0-\u05f2\u0621-\u063a\u0641-\u064a\u0671-\u06b7\u06ba-\u06be\u06c0-\u06ce\u06d0-\u06d3\u06d5\u06e5-\u06e6\u0905-\u0939\u093d\u0958-\u0961\u0985-\u098c\u098f-\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09dc-\u09dd\u09df-\u09e1\u09f0-\u09f1\u0a05-\u0a0a\u0a0f-\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32-\u0a33\u0a35-\u0a36\u0a38-\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8b\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2-\u0ab3\u0ab5-\u0ab9\u0abd\u0ae0\u0b05-\u0b0c\u0b0f-\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32-\u0b33\u0b36-\u0b39\u0b3d\u0b5c-\u0b5d\u0b5f-\u0b61\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99-\u0b9a\u0b9c\u0b9e-\u0b9f\u0ba3-\u0ba4\u0ba8-\u0baa\u0bae-\u0bb5\u0bb7-\u0bb9\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c33\u0c35-\u0c39\u0c60-\u0c61\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cde\u0ce0-\u0ce1\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d28\u0d2a-\u0d39\u0d60-\u0d61\u0e01-\u0e2e\u0e30\u0e32-\u0e33\u0e40-\u0e45\u0e81-\u0e82\u0e84\u0e87-\u0e88\u0e8a\u0e8d\u0e94-\u0e97\u0e99-\u0e9f\u0ea1-\u0ea3\u0ea5\u0ea7\u0eaa-\u0eab\u0ead-\u0eae\u0eb0\u0eb2-\u0eb3\u0ebd\u0ec0-\u0ec4\u0f40-\u0f47\u0f49-\u0f69\u10a0-\u10c5\u10d0-\u10f6\u1100\u1102-\u1103\u1105-\u1107\u1109\u110b-\u110c\u110e-\u1112\u113c\u113e\u1140\u114c\u114e\u1150\u1154-\u1155\u1159\u115f-\u1161\u1163\u1165\u1167\u1169\u116d-\u116e\u1172-\u1173\u1175\u119e\u11a8\u11ab\u11ae-\u11af\u11b7-\u11b8\u11ba\u11bc-\u11c2\u11eb\u11f0\u11f9\u1e00-\u1e9b\u1ea0-\u1ef9\u1f00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2126\u212a-\u212b\u212e\u2180-\u2182\u3041-\u3094\u30a1-\u30fa\u3105-\u312c\uac00-\ud7a3\u4e00-\u9fa5\u3007\u3021-\u30290-9\u0660-\u0669\u06f0-\u06f9\u0966-\u096f\u09e6-\u09ef\u0a66-\u0a6f\u0ae6-\u0aef\u0b66-\u0b6f\u0be7-\u0bef\u0c66-\u0c6f\u0ce6-\u0cef\u0d66-\u0d6f\u0e50-\u0e59\u0ed0-\u0ed9\u0f20-\u0f29\u0300-\u0345\u0360-\u0361\u0483-\u0486\u0591-\u05a1\u05a3-\u05b9\u05bb-\u05bd\u05bf\u05c1-\u05c2\u05c4\u064b-\u0652\u0670\u06d6-\u06dc\u06dd-\u06df\u06e0-\u06e4\u06e7-\u06e8\u06ea-\u06ed\u0901-\u0903\u093c\u093e-\u094c\u094d\u0951-\u0954\u0962-\u0963\u0981-\u0983\u09bc\u09be\u09bf\u09c0-\u09c4\u09c7-\u09c8\u09cb-\u09cd\u09d7\u09e2-\u09e3\u0a02\u0a3c\u0a3e\u0a3f\u0a40-\u0a42\u0a47-\u0a48\u0a4b-\u0a4d\u0a70-\u0a71\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0b01-\u0b03\u0b3c\u0b3e-\u0b43\u0b47-\u0b48\u0b4b-\u0b4d\u0b56-\u0b57\u0b82-\u0b83\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0c01-\u0c03\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55-\u0c56\u0c82-\u0c83\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5-\u0cd6\u0d02-\u0d03\u0d3e-\u0d43\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0eb1\u0eb4-\u0eb9\u0ebb-\u0ebc\u0ec8-\u0ecd\u0f18-\u0f19\u0f35\u0f37\u0f39\u0f3e\u0f3f\u0f71-\u0f84\u0f86-\u0f8b\u0f90-\u0f95\u0f97\u0f99-\u0fad\u0fb1-\u0fb7\u0fb9\u20d0-\u20dc\u20e1\u302a-\u302f\u3099\u309a\xb7\u02d0\u02d1\u0387\u0640\u0e46\u0ec6\u3005\u3031-\u3035\u309d-\u309e\u30fc-\u30fe]+')
  _Nmtoken11=("1.1",u'[-.0-9:A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u02ff\u0300-\u037d\u037f-\u1fff\u200c-\u200d\u203f-\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]+')
  _Name=("1.0",u'[_:A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u0131\u0134-\u013e\u0141-\u0148\u014a-\u017e\u0180-\u01c3\u01cd-\u01f0\u01f4-\u01f5\u01fa-\u0217\u0250-\u02a8\u02bb-\u02c1\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03ce\u03d0-\u03d6\u03da\u03dc\u03de\u03e0\u03e2-\u03f3\u0401-\u040c\u040e-\u044f\u0451-\u045c\u045e-\u0481\u0490-\u04c4\u04c7-\u04c8\u04cb-\u04cc\u04d0-\u04eb\u04ee-\u04f5\u04f8-\u04f9\u0531-\u0556\u0559\u0561-\u0586\u05d0-\u05ea\u05f0-\u05f2\u0621-\u063a\u0641-\u064a\u0671-\u06b7\u06ba-\u06be\u06c0-\u06ce\u06d0-\u06d3\u06d5\u06e5-\u06e6\u0905-\u0939\u093d\u0958-\u0961\u0985-\u098c\u098f-\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09dc-\u09dd\u09df-\u09e1\u09f0-\u09f1\u0a05-\u0a0a\u0a0f-\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32-\u0a33\u0a35-\u0a36\u0a38-\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8b\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2-\u0ab3\u0ab5-\u0ab9\u0abd\u0ae0\u0b05-\u0b0c\u0b0f-\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32-\u0b33\u0b36-\u0b39\u0b3d\u0b5c-\u0b5d\u0b5f-\u0b61\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99-\u0b9a\u0b9c\u0b9e-\u0b9f\u0ba3-\u0ba4\u0ba8-\u0baa\u0bae-\u0bb5\u0bb7-\u0bb9\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c33\u0c35-\u0c39\u0c60-\u0c61\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cde\u0ce0-\u0ce1\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d28\u0d2a-\u0d39\u0d60-\u0d61\u0e01-\u0e2e\u0e30\u0e32-\u0e33\u0e40-\u0e45\u0e81-\u0e82\u0e84\u0e87-\u0e88\u0e8a\u0e8d\u0e94-\u0e97\u0e99-\u0e9f\u0ea1-\u0ea3\u0ea5\u0ea7\u0eaa-\u0eab\u0ead-\u0eae\u0eb0\u0eb2-\u0eb3\u0ebd\u0ec0-\u0ec4\u0f40-\u0f47\u0f49-\u0f69\u10a0-\u10c5\u10d0-\u10f6\u1100\u1102-\u1103\u1105-\u1107\u1109\u110b-\u110c\u110e-\u1112\u113c\u113e\u1140\u114c\u114e\u1150\u1154-\u1155\u1159\u115f-\u1161\u1163\u1165\u1167\u1169\u116d-\u116e\u1172-\u1173\u1175\u119e\u11a8\u11ab\u11ae-\u11af\u11b7-\u11b8\u11ba\u11bc-\u11c2\u11eb\u11f0\u11f9\u1e00-\u1e9b\u1ea0-\u1ef9\u1f00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2126\u212a-\u212b\u212e\u2180-\u2182\u3041-\u3094\u30a1-\u30fa\u3105-\u312c\uac00-\ud7a3\u4e00-\u9fa5\u3007\u3021-\u3029][-._:A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u0131\u0134-\u013e\u0141-\u0148\u014a-\u017e\u0180-\u01c3\u01cd-\u01f0\u01f4-\u01f5\u01fa-\u0217\u0250-\u02a8\u02bb-\u02c1\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03ce\u03d0-\u03d6\u03da\u03dc\u03de\u03e0\u03e2-\u03f3\u0401-\u040c\u040e-\u044f\u0451-\u045c\u045e-\u0481\u0490-\u04c4\u04c7-\u04c8\u04cb-\u04cc\u04d0-\u04eb\u04ee-\u04f5\u04f8-\u04f9\u0531-\u0556\u0559\u0561-\u0586\u05d0-\u05ea\u05f0-\u05f2\u0621-\u063a\u0641-\u064a\u0671-\u06b7\u06ba-\u06be\u06c0-\u06ce\u06d0-\u06d3\u06d5\u06e5-\u06e6\u0905-\u0939\u093d\u0958-\u0961\u0985-\u098c\u098f-\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09dc-\u09dd\u09df-\u09e1\u09f0-\u09f1\u0a05-\u0a0a\u0a0f-\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32-\u0a33\u0a35-\u0a36\u0a38-\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8b\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2-\u0ab3\u0ab5-\u0ab9\u0abd\u0ae0\u0b05-\u0b0c\u0b0f-\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32-\u0b33\u0b36-\u0b39\u0b3d\u0b5c-\u0b5d\u0b5f-\u0b61\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99-\u0b9a\u0b9c\u0b9e-\u0b9f\u0ba3-\u0ba4\u0ba8-\u0baa\u0bae-\u0bb5\u0bb7-\u0bb9\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c33\u0c35-\u0c39\u0c60-\u0c61\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cde\u0ce0-\u0ce1\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d28\u0d2a-\u0d39\u0d60-\u0d61\u0e01-\u0e2e\u0e30\u0e32-\u0e33\u0e40-\u0e45\u0e81-\u0e82\u0e84\u0e87-\u0e88\u0e8a\u0e8d\u0e94-\u0e97\u0e99-\u0e9f\u0ea1-\u0ea3\u0ea5\u0ea7\u0eaa-\u0eab\u0ead-\u0eae\u0eb0\u0eb2-\u0eb3\u0ebd\u0ec0-\u0ec4\u0f40-\u0f47\u0f49-\u0f69\u10a0-\u10c5\u10d0-\u10f6\u1100\u1102-\u1103\u1105-\u1107\u1109\u110b-\u110c\u110e-\u1112\u113c\u113e\u1140\u114c\u114e\u1150\u1154-\u1155\u1159\u115f-\u1161\u1163\u1165\u1167\u1169\u116d-\u116e\u1172-\u1173\u1175\u119e\u11a8\u11ab\u11ae-\u11af\u11b7-\u11b8\u11ba\u11bc-\u11c2\u11eb\u11f0\u11f9\u1e00-\u1e9b\u1ea0-\u1ef9\u1f00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2126\u212a-\u212b\u212e\u2180-\u2182\u3041-\u3094\u30a1-\u30fa\u3105-\u312c\uac00-\ud7a3\u4e00-\u9fa5\u3007\u3021-\u30290-9\u0660-\u0669\u06f0-\u06f9\u0966-\u096f\u09e6-\u09ef\u0a66-\u0a6f\u0ae6-\u0aef\u0b66-\u0b6f\u0be7-\u0bef\u0c66-\u0c6f\u0ce6-\u0cef\u0d66-\u0d6f\u0e50-\u0e59\u0ed0-\u0ed9\u0f20-\u0f29\u0300-\u0345\u0360-\u0361\u0483-\u0486\u0591-\u05a1\u05a3-\u05b9\u05bb-\u05bd\u05bf\u05c1-\u05c2\u05c4\u064b-\u0652\u0670\u06d6-\u06dc\u06dd-\u06df\u06e0-\u06e4\u06e7-\u06e8\u06ea-\u06ed\u0901-\u0903\u093c\u093e-\u094c\u094d\u0951-\u0954\u0962-\u0963\u0981-\u0983\u09bc\u09be\u09bf\u09c0-\u09c4\u09c7-\u09c8\u09cb-\u09cd\u09d7\u09e2-\u09e3\u0a02\u0a3c\u0a3e\u0a3f\u0a40-\u0a42\u0a47-\u0a48\u0a4b-\u0a4d\u0a70-\u0a71\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0b01-\u0b03\u0b3c\u0b3e-\u0b43\u0b47-\u0b48\u0b4b-\u0b4d\u0b56-\u0b57\u0b82-\u0b83\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0c01-\u0c03\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55-\u0c56\u0c82-\u0c83\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5-\u0cd6\u0d02-\u0d03\u0d3e-\u0d43\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0eb1\u0eb4-\u0eb9\u0ebb-\u0ebc\u0ec8-\u0ecd\u0f18-\u0f19\u0f35\u0f37\u0f39\u0f3e\u0f3f\u0f71-\u0f84\u0f86-\u0f8b\u0f90-\u0f95\u0f97\u0f99-\u0fad\u0fb1-\u0fb7\u0fb9\u20d0-\u20dc\u20e1\u302a-\u302f\u3099\u309a\xb7\u02d0\u02d1\u0387\u0640\u0e46\u0ec6\u3005\u3031-\u3035\u309d-\u309e\u30fc-\u30fe]*')
  _Name11=("1.1",u'[:A-Z_a-z\xc0-\xd6\xd8-\xf6\xf8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c-\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd][-.0-9:A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u02ff\u0300-\u037d\u037f-\u1fff\u200c-\u200d\u203f-\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]*')
  _language="([a-zA-Z]{2}|[iI]-[a-zA-Z]+|[xX]-[a-zA-Z]+)(-[a-zA-Z]{1,8})*"
  _NCName="[^:]*"
  builtinPats.extend([_Name,_Name11,_Nmtoken,_Nmtoken11,_language,_NCName])
  builtinTypeNames.extend([
    ('normalizedString','string',((Whitespace,"replace"),),0),
    ('token','normalizedString',((Whitespace,"collapse"),),0),
    ('language','token',
    ((Pattern,[_language]),),0),
    ('NMTOKEN','token',((Pattern,[_Nmtoken,_Nmtoken11]),),0),
    ('Name','token',((Pattern,[_Name,_Name11]),),0),
    ('NCName','Name',((Pattern,[_NCName]),),0),
    ('ID','NCName',(),1), ('IDREF','NCName',(),2), ('ENTITY','NCName',(),0),
    ('aPDecimal','pDecimal',((LexicalMappings,['nodecimal', 'decimal']),
                             (Precision,0)),0),
    ('integer','decimal',((FractionDigits,0),),0),
    ('nonPositiveInteger','integer',((MaxInclusive,0),),0),
    ('negativeInteger','nonPositiveInteger', ((MaxInclusive,-1),),0),
    ('long','integer',((MinInclusive,-9223372036854775808L),
    (MaxInclusive,9223372036854775807L)),0),
    ('int','long',((MinInclusive,-2147483648L),(MaxInclusive,2147483647)),0),
    ('short','int',((MinInclusive,-32768),(MaxInclusive,32767)),0),
    ('byte','short',((MinInclusive,-128),(MaxInclusive,127)),0),
    ('nonNegativeInteger','integer',((MinInclusive,0),),0),
    ('unsignedLong','nonNegativeInteger',((MaxInclusive,18446744073709551615L),),0),
    ('unsignedInt','unsignedLong',((MaxInclusive,4294967295L),),0),
    ('unsignedShort','unsignedInt',((MaxInclusive,65535),),0),
    ('unsignedByte','unsignedShort',((MaxInclusive,255),),0),
    ('positiveInteger','nonNegativeInteger',((MinInclusive,1),),0)])

  XSV.NCNamePat = re.compile("(%s)$"%_Name[1]);
  XSV.NCNamePat11 = re.compile("(%s)$"%_Name11[1]);
Ejemplo n.º 43
0
 def init(self, iterable=list(), prefix='', suffix=''):
     List.__init__(self, iterable)
     self.prefix = prefix
     self.suffix = suffix
Ejemplo n.º 44
0
	def setUp(self):
		List.create_archive()
		self.l = List.List('Hack BG')
Ejemplo n.º 45
0
class ListNode(object):
    def __init__(self, x):
        self.val = x
        self.next = None

l1 = ListNode(1)
l2 = ListNode(4)
l3 = ListNode(3)
l4 = ListNode(2)
l5 = ListNode(5)
l6 = ListNode(2)
# l7 = ListNode(7)
# l8 = ListNode(8)
# l9 = ListNode(9)

l1.next = l2
l2.next = l3
l3.next = l4
l4.next = l5
l5.next = l6
# l6.next = l7
# l7.next = l8
# l8.next = l9

s = d.Solution()
List.printList(s.insertionSortList(l1))



Ejemplo n.º 46
0
def main():
    run(List.create(25), 100000)
Ejemplo n.º 47
0
    def make_instance(typeclass, cls, foldr, foldr1=None, foldl=None,
            foldl_=None, foldl1=None, toList=None, null=None, length=None,
            elem=None, maximum=None, minimum=None, sum=None, product=None):

        # attributes that are not supplied are implemented in terms of toList
        if toList is None:
            if hasattr(cls, "__iter__"):
                toList = lambda x: L[iter(x)]
            else:
                toList = lambda t: foldr(lambda x, y: x ^ y, L[[]], t)

        foldr1 = (lambda x: DL.foldr1(toList(x))) if foldr1 is None else foldr1
        foldl = (lambda x: DL.foldl(toList(x))) if foldl is None else foldl
        foldl_ = (lambda x: DL.foldl_(toList(x))) if foldl_ is None else foldl_
        foldl1 = (lambda x: DL.foldl1(toList(x))) if foldl1 is None else foldl1
        null = (lambda x: DL.null(toList(x))) if null is None else null
        length = (lambda x: DL.length(toList(x))) if length is None else length
        elem = (lambda x: DL.length(toList(x))) if length is None else length
        mi = (lambda x: DL.minimum(toList(x))) if minimum is None else minimum
        ma = (lambda x: DL.maximum(toList(x))) if maximum is None else maximum
        sum = (lambda x: DL.sum(toList(x))) if sum is None else sum
        p = (lambda x: DL.product(toList(x))) if product is None else product


        attrs = {"foldr":foldr, "foldr1":foldr1, "foldl":foldl,
                "foldl_":foldl_, "foldl1":foldl1, "toList":toList, "null":null,
                "length":length, "elem":elem, "maximum":ma, "minimum":mi,
                "sum":sum, "product":p}
        build_instance(Foldable, cls, attrs)

        if not hasattr(cls, "__len__") and not is_builtin(cls):
            cls.__len__ = length

        if not hasattr(cls, "__iter__") and not is_builtin(cls):
            cls.__iter__ = lambda x: iter(toList(x))
        return
Ejemplo n.º 48
0
	def test_get_arguments(self):
		c = "merge 1 2 HACK_LIST"
		a = List.get_arguments(c, 3)
		self.assertEqual(['1', '2', 'HACK_LIST'], a)
Ejemplo n.º 49
0
	def test_get_valid_filename(self):
		list_name = "Hack BG Not Valid Filename"
		self.assertEqual("Hack_BG_Not_Valid_Filename.txt", List.get_valid_filename(list_name))
		list_name = "HackBG"
		self.assertEqual("HackBG.txt", List.get_valid_filename(list_name))
		line_of_file = "[1] John Smith - [email protected]"