def get_the_most_frequent_buyers_ids(num=1): """ Returns 'num' number of buyers (more precisely: the customer ids of them) who bought more frequent in an ordered list of tuples of customer id and the number their sales. Args: num: the number of the customers to return. Returns: list of tuples: Ordered list of tuples of customer ids and num of sales The first one bought the most frequent. eg.: [(aH34Jq#&, 8), (bH34Jq#&, 3)] """ tmp = [] tmp_ordered = [] dictionary = sales.get_num_of_sales_per_customer_ids() for key, value in dictionary.items(): tmp.append((key, value)) while tmp: maximum_value = tmp[0][1] maximum = tmp[0] for i in range(len(tmp)): if tmp[i][1] > maximum_value: maximum_value = tmp[i][1] maximum = tmp[i] tmp_ordered.append(maximum) tmp.remove(maximum) if len(tmp_ordered) == num: return (tmp_ordered)
def get_the_most_frequent_buyers_names(num=1): """ Returns 'num' number of buyers (more precisely: the customer's name) who bought most frequently in an ordered list of tuples of customer names and the number of their sales. Args: num: the number of the customers to return. Returns: list of tuples: Ordered list of tuples of customer names and num of sales The first one bought the most frequent. eg.: [('Genoveva Dingess', 8), ('Missy Stoney', 3)] """ tmp = [] tmp_ordered = [] dictionary = sales.get_num_of_sales_per_customer_ids() for key, value in dictionary.items(): tmp.append((crm.get_name_by_id(key), value)) while tmp: maximum_value = tmp[0][1] maximum = tmp[0] for i in range(len(tmp)): if tmp[i][1] > maximum_value: maximum_value = tmp[i][1] maximum = tmp[i] tmp_ordered.append(maximum) tmp.remove(maximum) if len(tmp_ordered) == num: return (tmp_ordered)
def get_the_most_frequent_buyers_ids(num=1): """ Returns 'num' number of buyers (more precisely: the customer ids of them) who bought more frequent. Returns an ordered list of tuples of customer id and the number their sales. (The first one bought the most frequent.) eg.: [(aH34Jq#&, 8), (bH34Jq#&, 3)] Args: num: the number of the customers to return. Returns: Ordered list of tuples of customer ids and num of sales """ customers = sales.get_num_of_sales_per_customer_ids() customers = list(customers.items()) requested_list = [] try: int(num) <= len(requested_list) for buyer in range(int(num)): request = customers[buyer] requested_list.append(request) except IndexError: ui.print_error_message("There are less customers in the database.") return [requested_list]
def get_the_most_frequent_buyers_names(num=1): """ Returns 'num' number of buyers (more precisely: the customer's name) who bought most frequently in an ordered list of tuples of customer names and the number of their sales. Args: num: the number of the customers to return. Returns: list of tuples: Ordered list of tuples of customer names and num of sales The first one bought the most frequent. eg.: [('Genoveva Dingess', 8), ('Missy Stoney', 3)] """ # 5 most_sales = sales.get_num_of_sales_per_customer_ids() most_frequent = [] for number in range(num): id_ = '' for key, value in most_sales.items(): if value == max(most_sales.values()): id_ = key name = crm.get_name_by_id(id_) most_frequent.append((name, max(most_sales.values()))) most_sales.pop(id_) return most_frequent
def get_the_most_frequent_buyers_names(num=1): """ Returns 'num' number of buyers (more precisely: the customers' name) who bought most frequently. Returns an ordered list of tuples of customer names and the number of their sales. (The first one bought the most frequent.) eg.: [(aH34Jq#&, 8), (bH34Jq#&, 3)] Args: num: the number of the customers to return. Returns: Ordered list of tuples of customer names and num of sales """ # {'kH14Jt#&': 8, 'jH34Jk#&': 11, 'kH14Jh#&': 1} cust_id_and_sum_of_buyed_items = sales.get_num_of_sales_per_customer_ids() for key, value in sorted(cust_id_and_sum_of_buyed_items.items(), key=lambda x: x[1], reverse=True)[num:]: del cust_id_and_sum_of_buyed_items[key] cust_ids = list(cust_id_and_sum_of_buyed_items) cust_names = [] for elem in cust_ids: cust_name = crm.get_name_by_id(elem) cust_names.append(cust_name) for key, val in cust_id_and_sum_of_buyed_items.items(): i = 1 cust_names.insert(i, val) return cust_names
def get_the_most_frequent_buyers_names(num=1): temp = sales.get_num_of_sales_per_customer_ids() temp = sorted(temp.items(), key=lambda item: item[1], reverse=True) result = [] for i in range(len(temp)): name_and_id = (crm.get_name_by_id(temp[i][0]), temp[i][1]) result.append(name_and_id) return result[:num]
def get_the_most_frequent_buyers_ids(num=1): dict = sales.get_num_of_sales_per_customer_ids() my_lst = [] for i in dict: appendable = [i, dict[i]] my_lst.append(appendable) my_lst.sort(key=lambda x: x[1], reverse=True) for i in range(len(my_lst)): my_lst[i] = tuple(my_lst[i]) return my_lst[0:num]
def get_the_most_frequent_buyers_ids(num=1): result = [] all_customers = [] number_of_sales = [] customer_sales = sales.get_num_of_sales_per_customer_ids() for i in sorted(customer_sales, key=customer_sales.get, reverse=True): all_customers.append(tuple([i, customer_sales[i]])) if num > len(all_customers): num = len(all_customers) for i in range(0, num): result.append(all_customers[i]) return result
def get_the_buyer_id_spent_most_and_the_money_spent(): """ Returns the customer's _id_ who spent more in sum and the money (s)he spent. Returns: tuple: Tuple of customer id and the sum the customer spent eg.: (aH34Jq#&, 42) """ # 4 most_sales = sales.get_num_of_sales_per_customer_ids() id_ = '' for key, value in most_sales.items(): if value == max(most_sales.values()): id_ = key all_sale_ids = sales.get_all_sales_ids_for_customer_ids() sum_sales = sales.get_the_sum_of_prices(all_sale_ids[id_]) return (id_, sum_sales)
def get_the_most_frequent_buyers_ids(num=1): # Max """ Returns 'num' number of buyers (more precisely: the customer ids of them) who bought more frequent in an ordered list of tuples of customer id and the number their sales. Args: num: the number of the customers to return. Returns: list of tuples: Ordered list of tuples of customer ids and num of sales The first one bought the most frequent. eg.: [(aH34Jq#&, 8), (bH34Jq#&, 3)] """ result_lst = [] sales_per_customer = sales.get_num_of_sales_per_customer_ids() for ID, NUM_OF_PURCHASES in sales_per_customer.items(): tuple_of_customer = (ID, NUM_OF_PURCHASES) result_lst.append(tuple_of_customer) return result_lst[:num]
def get_the_most_frequent_buyers_names(num=1): # Max """ Returns 'num' number of buyers (more precisely: the customer's name) who bought most frequently in an ordered list of tuples of customer names and the number of their sales. Args: num: the number of the customers to return. Returns: list of tuples: Ordered list of tuples of customer names and num of sales The first one bought the most frequent. eg.: [('Genoveva Dingess', 8), ('Missy Stoney', 3)] """ result_lst = [] sales_per_customer = sales.get_num_of_sales_per_customer_ids() for ID, NUM_OF_PURCHASES in sales_per_customer.items(): tuple_of_customer = ((crm.get_name_by_id(ID)), NUM_OF_PURCHASES) result_lst.append(tuple_of_customer) return result_lst[:num]
def get_the_buyer_name_spent_most_and_the_money_spent(): """ Returns the customer's _name_ who spent the most in sum and the money (s)he spent. Returns: tuple: Tuple of customer name and the sum the customer spent eg.: ('Daniele Coach', 42) """ # 3 most_sales = sales.get_num_of_sales_per_customer_ids() id_ = '' for key, value in most_sales.items(): if value == max(most_sales.values()): id_ = key name = crm.get_name_by_id(id_) all_sale_ids = sales.get_all_sales_ids_for_customer_ids() sum_sales = sales.get_the_sum_of_prices(all_sale_ids[id_]) return (name, sum_sales)
def get_the_most_frequent_buyers_ids(num=1): """ Returns 'num' number of buyers (more precisely: the customer ids of them) who bought more frequent in an ordered list of tuples of customer id and the number their sales. Args: num: the number of the customers to return. Returns: list of tuples: Ordered list of tuples of customer ids and num of sales The first one bought the most frequent. eg.: [(aH34Jq#&, 8), (bH34Jq#&, 3)] """ names = sales.get_num_of_sales_per_customer_ids() new_dict = {} for key, values in names.items(): new_dict.update({key: values}) new_list = list(new_dict.items()) return new_list[:num]
def get_the_most_frequent_buyers_ids(num=1): """ Returns 'num' number of buyers (more precisely: the customer ids of them) who bought more frequent in an ordered list of tuples of customer id and the number their sales. Args: num: the number of the customers to return. Returns: list of tuples: Ordered list of tuples of customer ids and num of sales The first one bought the most frequent. eg.: [(aH34Jq#&, 8), (bH34Jq#&, 3)] """ # your code all_customer = [] all_customer_ids_sales_ids = sales.get_num_of_sales_per_customer_ids() for customer_ids in all_customer_ids_sales_ids.keys(): all_customer.append((customer_ids, all_customer_ids_sales_ids[customer_ids])) return all_customer
def get_the_most_frequent_buyers_names(num=1): """ Returns 'num' number of buyers (more precisely: the customer's name) who bought most frequently in an ordered list of tuples of customer names and the number of their sales. Args: num: the number of the customers to return. Returns: list of tuples: Ordered list of tuples of customer names and num of sales The first one bought the most frequent. eg.: [('Genoveva Dingess', 8), ('Missy Stoney', 3)] """ # your code all_customer = [] all_customer_ids_sales_ids = sales.get_num_of_sales_per_customer_ids() for customer_ids in all_customer_ids_sales_ids.keys(): all_customer.append((crm.get_name_by_id(customer_ids), all_customer_ids_sales_ids[customer_ids])) return all_customer
def get_the_most_frequent_buyers_names(num=1): """ Returns 'num' number of buyers (more precisely: the customer's name) who bought most frequently in an ordered list of tuples of customer names and the number of their sales. Args: num: the number of the customers to return. Returns: list of tuples: Ordered list of tuples of customer names and num of sales The first one bought the most frequent. eg.: [('Genoveva Dingess', 8), ('Missy Stoney', 3)] """ names = sales.get_num_of_sales_per_customer_ids() new_dict = {} for key, values in names.items(): new_dict.update({crm.get_name_by_id(key): values}) new_list = list(new_dict.items()) return new_list[:num]
def get_the_most_frequent_buyers_ids(num=1): """ Returns 'num' number of buyers (more precisely: the customer ids of them) who bought more frequent. Returns an ordered list of tuples of customer id and the number their sales. (The first one bought the most frequent.) eg.: [(aH34Jq#&, 8), (bH34Jq#&, 3)] Args: num: the number of the customers to return. Returns: Ordered list of tuples of customer ids and num of sales """ # {'kH14Jt#&': 8, 'jH34Jk#&': 11, 'kH14Jh#&': 1} cust_id_and_sum_of_buyed_items = sales.get_num_of_sales_per_customer_ids() for key, value in sorted(cust_id_and_sum_of_buyed_items.items(), key=lambda x: x[1], reverse=True)[num:]: del cust_id_and_sum_of_buyed_items[key] # result_list = [] # result_list.append(set(cust_id_and_sum_of_buyed_items.items())) # return result_list return cust_id_and_sum_of_buyed_items
def get_the_most_frequent_buyers_ids(num=1): """ Returns 'num' number of buyers (more precisely: the customer ids of them) who bought more frequent in an ordered list of tuples of customer id and the number their sales. Args: num: the number of the customers to return. Returns: list of tuples: Ordered list of tuples of customer ids and num of sales The first one bought the most frequent. eg.: [(aH34Jq#&, 8), (bH34Jq#&, 3)] """ working_dictionary = sales.get_num_of_sales_per_customer_ids() customer_ID_sales_amount = [] for key, value in working_dictionary.items(): customer_ID_sales_amount.append((key, value)) result = [] i = 0 while i < num: result.append(customer_ID_sales_amount[i]) i += 1 return result
def get_the_most_frequent_buyers_ids(num=1): """ Returns 'num' number of buyers (more precisely: the customer ids of them) who bought more frequent in an ordered list of tuples of customer id and the number their sales. Args: num: the number of the customers to return. Returns: list of tuples: Ordered list of tuples of customer ids and num of sales The first one bought the most frequent. eg.: [(aH34Jq#&, 8), (bH34Jq#&, 3)] """ # 6 most_sales = sales.get_num_of_sales_per_customer_ids() most_frequent = [] for number in range(num): id_ = '' for key, value in most_sales.items(): if value == max(most_sales.values()): id_ = key most_frequent.append((id_, max(most_sales.values()))) most_sales.pop(id_) return most_frequent
def get_the_most_frequent_buyers_ids(num=1): result = sales.get_num_of_sales_per_customer_ids() result = sorted(result.items(), key=lambda item: item[1], reverse=True) return result[:num]