Shoe shop¶
The supplies of a shoe shop are represented by a list of articles corresponding to shoe sizes. An article is represented with a list of two integers that stand for, respectively, the size and the number of pairs of shoes of this size stored in the shoe shop. The list of articles is not ordered according to any criteria and each size only appears once.
Write the function
shoeshop1()that from a list of articles and two integers corresponding to two sizes,s1ands2, returns that size betweens1ands2(both included) with the maximum number of pairs of shoes. If there were more than one size fulfilling these requirements, the first one encountered must be returned. If there is any size fulfilling these requirements, or the given list is empty, the function will return -1. Save this function into the fileshoeshop1.py. Examples:>>> lshoes = [[30, 4], [45, 5], [36, 8], [37, 12], [42, 6], [28, 11], [32, 8], ... [34, 9], [41, 4], [38, 6], [44, 7], [33, 8], [40, 5], [35, 7], [39, 12], ... [29, 9], [31, 5], [43, 12]] >>> shoeshop1(lshoes, 35, 40) 37 >>> shoeshop1(lshoes, 40, 45) 43 >>> shoeshop1([], 40, 45) -1 >>> lshoes = [[30, 4], [45, 5], [36, 8], [37, 12], [42, 6], [28, 11]] >>> shoeshop1(lshoes, 31, 35) -1 >>> shoeshop1(lshoes, 28, 30) 28
Note
More tests are provided in file
test-shoeshop1.txtSolution
A solution of this function is provided in the
shoeshop1.pySave this function as well as the next ones into the same file
shoeshop2.py. Write the functionsearch_size()that from a list of articles and an integer indicating a size, returns the position in the list of articles of the article corresponding to that size. If the size does not appear in the list of articles, this function must return -1. Examples:>>> stock =[[30, 4], [45, 5], [36, 8], [37, 12], [42, 6], [32, 8], ... [34, 9], [41, 4], [38, 6], [44, 7], [33, 8], [40, 5], [35, 7], [39, 12], ... [29, 9], [31, 5]] >>> search_size (stock, 36) 2 >>> search_size (stock, 41) 7 >>> search_size (stock, 28) -1
Note
More tests are provided in file
test-shoeshop2.txtWrite the modifier function
update_size()that from a list of articles, an integer indicating the position of an article and another integer indicating a number of pairs of shoes, updates the list by increasing the units of the article corresponding to the given position with the given amount of pairs of shoes. Examples:>>> stock =[[30, 4], [45, 5], [36, 8], [37, 12], [42, 6], [32, 8], ... [34, 9], [41, 4], [38, 6], [44, 7], [33, 8], [40, 5], [35, 7], [39, 12], ... [29, 9], [31, 5]] >>> update_size (stock, 2, 1) >>> stock == [[30, 4], [45, 5], [36, 9], [37, 12], [42, 6], [32, 8], ... [34, 9], [41, 4], [38, 6], [44, 7], [33, 8], [40, 5], [35, 7], [39, 12], ... [29, 9], [31, 5]] True >>> update_size (stock, 7, 4) >>> stock == [[30, 4], [45, 5], [36, 9], [37, 12], [42, 6], [32, 8], ... [34, 9], [41, 8], [38, 6], [44, 7], [33, 8], [40, 5], [35, 7], [39, 12], ... [29, 9], [31, 5]] True
Note
More tests are provided in file
test-shoeshop3.txtWrite the modifier function
update_stock()that given a list of items corresponding to the supplies of the shoe shop and another list of articles corresponding to new pairs of shoes entering to the shop, updates the first list with the entries in the second list. This function must call the previous two functions. Examples:>>> stock =[[30, 4], [45, 5], [36, 8], [37, 12], [42, 6], [32, 8], ... [34, 9], [41, 4], [38, 6], [44, 7], [33, 8], [40, 5], [35, 7], [39, 12], ... [29, 9], [31, 5]] >>> entries = [[36, 1], [37, 2], [28, 3], [32, 1], [41, 4], [43, 2]] >>> update_stock(stock, entries) >>> stock == [[30, 4], [45, 5], [36, 9], [37, 14], [42, 6], [32, 9], ... [34, 9], [41, 8], [38, 6], [44, 7], [33, 8], [40, 5], [35, 7], [39, 12], ... [29, 9], [31, 5], [28, 3], [43, 2]] True
Note
More tests are provided in file
test-shoeshop4.txtSolution
A solution of this function and the two previous ones is provided in file
shoeshop2.py