Ejemplo n.º 1
0
    def extend(self,x):
        h = None
	if len(self)>0:
	    h = self[0]
	deque.extend(self, x)
	if ( len(self)>0 and h!=self[0] ):
	    self[0].handle_head_of_queue()
def invertBinaryTree(tree):
    que = [tree]
    while len(que) > 0:
        current = que.popleft()
        if current is None:
            continue
        current.left, current.right = current.right, current.left
        que.extend([current.left, current.right])
Ejemplo n.º 3
0
 def solve(self):
     # use priority queue for weight
     queue = deque()
     queue.append(self.state)
     while not queue.isEmpty():
         current = queue.popleft()
         if current.is_goal():
             # possible print
             return current
         deque.extend(current.get_children())
Ejemplo n.º 4
0
 def extendleft(self, iterable):
     deque.extend(self, iterable)
     for i in range(0, len(iterable)):
         self.__size_sema.release()
Ejemplo n.º 5
0
#functions of deque.

from collections import deque

deque = deque([1,2,3])


#extend vs aappend

print('Extend function.')
deque.extend('456')
deque.extend([7,8,9])
print(deque)

print('Append function.')
deque.append('abc')
deque.append(['d','e','f'])
print(deque)


#other functions.

print('Search index.')
# index(ele, beg, end)
print(deque.index(7,5,9))

print('Count')
print(deque.count(0))

print('Extend Left')
deque.extendleft([0])
Ejemplo n.º 6
0
 def extendleft(self, iterable):
     deque.extend(self, iterable)
     for i in range(0, len(iterable)):
         self.__size_sema.release()
Ejemplo n.º 7
0
user_name = userlist.popleft()
userlist1 = ["1", "2", "3"]
user_name1 = userlist1.pop(0)
print(user_name1)
print(user_name)
from queue import Queue
yyy = Queue()
print(yyy.empty())
yyy.put(5)
print(yyy.empty())
yyy.get(2, 0.5)
print(yyy.qsize())
# deque GIL是线程安全的,list不是线程安全的
# deque的拷贝是浅拷贝,虽然id不同,但是dequeue里是一个对象的时候,也会改变
user_deque = deque(["bobby1", ["bobby2", "bobby3"], "bobby3"])
user_deque_copy = user_deque.copy()
user_deque[1].append(1)
user_deque[0] = "1"
print(user_deque)
print(user_deque_copy)
'''
# 深拷贝
import copy
deep=copy.deepcopy(user_deque)
# 动态的扩容
deque.extend()
'''
list1 = [1, 2, 5, 8, 9]
list1.pop(0)
list1.insert(0, 5)
print(list1)
Ejemplo n.º 8
0
 def CMD_rpush(self, key, *values):
     print("pushing - ", key, values)
     deque = self.dictionary.get(key, collections.deque())
     deque.extend(values)
     self.dictionary[key] = deque
     return b":%d\r\n" % (len(deque), )
Ejemplo n.º 9
0
 def rpush(self, key, *values):
     deque = self.dictionary.get(key, collections.deque())
     deque.extend(values)
     self.dictionary[key] = deque
     return b":%d\r\n" % (len(deque), )