Ad
Mathematics
Algorithms
Logic
Numbers
Data Types
Code
Diff
  • my_tuple = ((10, 10, 10, 12), (30, 45, 56, 45), (81, 80, 39, 32), (1, 2, 3, 4))
    
    
    def average(tuples):
        return [sum(i) / len(i) for i in zip(*tuples)]
    
    
    print(f"\nAverage value: {average(my_tuple)}")
    • my_tuple = ((10, 10, 10, 12), (30, 45, 56, 45), (81, 80, 39, 32), (1, 2, 3, 4))
    • def average(tuples):
    • output_list = []
    • for item in zip(*tuples):
    • output_list.append(sum(item)/len(item))
    • return output_list
    • return [sum(i) / len(i) for i in zip(*tuples)]
    • print(f"\nAverage value: {average(my_tuple)}")
Code
Diff
  • mylist = [("yellow", 1), ("blue", 2), ("yellow", 3), ("blue", 4), ("red", 1)]
    
    
    def group(lst, result={}):
        {result[c].append(n) if c in result else result.update({c: [n]}) for c, n in lst}
        return result
    
    
    print(group(mylist))
    • mylist = [('yellow', 1), ('blue', 2), ('yellow', 3), ('blue', 4), ('red', 1)]
    • mylist = [("yellow", 1), ("blue", 2), ("yellow", 3), ("blue", 4), ("red", 1)]
    • def group(lst):
    • dic = {}
    • for i in lst:
    • if i[0] not in dic:
    • dic[i[0]] = [i[1]]
    • else:
    • dic[i[0]] = [*dic[i[0]], i[1]]
    • return dic
    • def group(lst, result={}):
    • {result[c].append(n) if c in result else result.update({c: [n]}) for c, n in lst}
    • return result
    • print(group(mylist))