def dictionary_list(): second_llist = LList() combinations_in_dictionary = {} file = open("10-million-combos.txt", "r") # SAME PROCESS TO READ THE TEXT FILE line = file.readline() for line in file: line = line.strip().split(" ") username = line[0] password = line[-1] if password in combinations_in_dictionary: # IF THE PASSWORD WERE TO ALREADY BE THERE, THE COUNT ONLY INCREASES combinations_in_dictionary[password].count += 1 else: # IF PASSWORD WAS NOT IN THE DICTIONARY THEN NEW NODE IS CREATED AND DICTIONARY STORES THE LOCATION second_llist.head = Node(password, 1, second_llist.head) combinations_in_dictionary[password] = second_llist.head file.close() # METHOD CREATED TO CHECK IF LINKED LIST WAS BEING CREATED # tmp = second_llist.head # while tmp is not None: # print(tmp.password, tmp.count) # tmp = tmp.next return second_llist
def main(): first_list = LList() first_list = read_create_combinations() bubble_sort(first_list) second_list = LList() second_list = dictionary_list() bubble_sort(second_list)
def ConvertWordListToCharList(inputList): """ This will take in our wordList/charList that's used to encode/decode our string and will return the distinct individual characters of all those strings :param inputList: The list of individual words :return: The distinct characters contained in our list of words/characters """ charList = LList() for word in inputList: for char in word: if not charList.__contains__(char): charList.append(char) return charList
def StringCompression(subList, fullString): """ :param subList: A list of words/characters used to encode/decode :param fullString: A string we want to encode into integers :return: Our encoded string """ #Get the disctint individual characters from subList subCharList = ConvertWordListToCharList(subList) encodedString = LList() #Iterate thru the string we want to encode #Find the index of the current character in the subCharList #Make that index the encoded character and move on to next char for char in fullString: index = subCharList.index(char) encodedString.append(index) return encodedString
def read_create_combinations(): first_list = LList() file = open("10-million-combos.txt", "r") line = file.readline() for line in file: line = line.strip().split(" ") # SPLITS THE LINE INTO INDEXES OF AN ARRAY username = line[0] password = line[-1] # INDEX IN ARRAY WHICH CONTAINS PASSWORD # print(password) # CALLS METHODS TO CHECKS IF THE PASSWORD HAS BEEN REPEATED if not check_duplicate(password, first_list): # If password was not found: first_list.head = Node(password, 1, first_list.head) # WILL CREATE NEW NODE INTO LLIST WHICH WILL BE HEAD file.close() return first_list
def main(): print("Make a linked list -> 1 -> 2 -> 3 -> None") mylist = LList(( 1, 2, 3)) # call constructor with the tuple ( 1 , 2 , 3) for item in mylist: print(str(item)+"->",end='') print("None") print("mylist[0] is "+ str(mylist[0])) # calls a. __ get item _ (O) mylist[0] = 4 # calls a. __ set item _ ( O , 4 ) print("Change mylist[0]") print("mylist[0] is "+ str(mylist[0])) # calls a. __ get item _ (O) for item in mylist: print(str(item)+"->",end='') print("None")
def create_list(vivendi_ids, activision_ids): all_ids = LList() for id in vivendi_ids: num_id = int(id) node = Node(num_id) all_ids.append(node) for id in activision_ids: num_id = int(id) node = Node(num_id) all_ids.append(node) return all_ids
def main(): print("Make a linked list in honor of Donna Schmidt") mom = LList( (8, 21, 1962) ) # Named after Donna Schmidt, my mom because she is the strongest willed person I know print("Make a linked list in honor of Jim Carrey") truman = LList( (6, 17, 1962) ) # Named after Jim Carrey because he is always his true with himself and others about who he is print("Make a linked list for a fictional character") fictional = LList( ((8 + 6) // 2, (21 + 17) // 2, 1962)) # Fictional persons birthday # Printing the Birthdays # --------------------------------------------------------------------------------------- print("\n") print("Printing Donna's birthday") for item in mom: print(str(item) + " ", ) print("\n") print("Printing Jim Carrey's birthday") for item in truman: print(str(item) + " ", ) print("\n") print("Printing the fictional character's birthday") for item in fictional: print(str(item) + " ", ) # Changing the year of the fictional character # --------------------------------------------------------------------------------------- year = fictional._find(len(fictional) - 1) year.item += 100 print("\n") print("Printing the fictional character's revised birthday") for item in fictional: print(str(item) + " ", ) # Deleting the date of the fictional character's birthday # ---------------------------------------------------------------------------------------- fictional.__delitem__(1) print("\n") print("Printing the fictional character's revised birthday") for item in fictional: print(str(item) + " ", )
def read_numbers_return_list(): '''preconditions: none postconditions: the numbers in the file with the name asked by the user will be placed into a linked list and returned.''' filename = input("What is the name of the file?") file = open(filename, "r") # get the list of strings from the file. This list will need to be converted to # a list of numbers in a stringList = file.read().split() file.close() # time to create an integer version of the numbers list numberList = [] for item in stringList: numberList.append(int(item)) # Now create a linked list version of this number sequence created_list = LList(numberList) return created_list
def __init__(self): LList.__init__(self) self.rear = None # 尾节点引用域
'''simple driver for LList''' from LList import LList print( "Creating linked-list of characters starting with ->h->e->l->l->0->NULL") testingList = LList("hello") print("Finding the 4th item in the list: ") print( testingList.__getitem__(4)) print("alternative coding for finding the 4th item in the list: ") print(testingList[4]) print("Inserting '!' in the fifth position: ") testingList.insert(5, '!') print(testingList[5])
def __init__(self): LList.__init__(self) #先初始化父类LList的数据 self._rear = None
self._rear.next = LNode(elem) self._rear = self._rear.next def pop_last(self): if self._head is Node: raise LinkedListUnderflow("in pop_last") p = self._head if p.next is None: e = p.elem self._head = None return e while p.next.next: p = p.next e = p.next.elem p.next = None self._rear = p if __name__ == '__main__': lst = LList() for i in range(10): lst.prepend(i) for i in range(11, 20): lst.append(randint(1, 20)) for x in lst.elements(): print(x, end=',') print('') for x in lst.filter(lambda y: y % 2 == 0): print(x, end=',')
p = p.next if q is None: llist._head = rem else: q.next = rem q = rem rem = rem.next q.next = p if __name__ == '__main__': # 创建顺序表对象 seq1 = seq_list() # 创建单链表对象 llist = LList() # 创建排序对象 sort_temp = sort() # 向顺序表中插入数据 for i in range(seq1.max): seq1.append(random.randint(1, 50)) # 向单链表中插入数据 for i in range(10): llist.append(random.randint(1, 100)) # 输出顺序表数据 # seq1.showall() # 输出单链表数据
def __init__(self): LList.__init__(self)
def __init__(self): LList.__init__(self) self._rear = None
'''simple driver for LList''' from LList import LList print("Creating linked-list of characters starting with ->h->e->l->l->0->NULL") testingList = LList("hello") print("Finding the 4th item in the list: ") print(testingList.__getitem__(4)) print("alternative coding for finding the 4th item in the list: ") print(testingList[4]) print("Inserting '!' in the fifth position: ") testingList.insert(5, '!') print(testingList[5])