-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
134 lines (86 loc) · 2.59 KB
/
Copy pathtest.py
File metadata and controls
134 lines (86 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import pandas as pd
# labels = pd.read_csv("D:/MSCS/ADL/Data/train.csv")
# print(len(labels))
# print(labels.iloc[[0,1], 0])
# print(labels.iloc[[0,1], 1])
# f = 3, cit = [1,3,6,4]
# n = len(1,3,6,4)
# res =[]
# def feul(s,d):
# return s-d
# def backtrack(source,destinations,re,f,j):
# #cost = fuel(source,destinations[0])
# if destinations:
# cost = fuel(source,destinations[j])
# if f == cost:
# re.append(cit[i+1])
# f = 0
# if f < cost:
# pass #check for other case
# backtrack(source,destination,re,f)
# if f > cost:
# pass # continue for going forward and also update f
# re.append(destinations[j])
# backtrack(destinations[j],destinations[j+1:],re,f-c)
# else:
# return
# for i in range(0,n-1):
# j = 0
# backtrack(cit[0], cit[i+1:], res, f,j)
# def slowestKey(keyTimes):
# alphabet = 'abcdefghijklmnopqrstuvwxyz'
# alpha_dict = {}
# for i in range(0,len(alphabet)):
# alpha_dict[i] = alphabet[i]
# for i in range(len(keyTimes)-1, 0, -1):
# keyTimes[i][1] -= keyTimes[i-1][1]
# return alpha_dict[max(keyTimes, key = lambda x : x[1])[0]]
# print(slowestKey([[0,2],[1,3],[0,7]]))
# print(slowestKey([[0,1],[0,3],[4,5],[5,6],[4,10]]))
# dict1 = {}
# for i in products:
# if i in dict1.keys():
# dict1[i] += 1
# else:
# dict1[i] = 1
for i in range(0,1):
print(i)
exit()
from functools import cmp_to_key
def compare(item1, item2):
if item1[1] != item2[1]:
return item1[1] - item2[1]
else:
if item1[0] <= item2[0]:
return -1
else:
return 1
def featuredProducts(products):
freq = {}
for item in products:
if item not in freq:
freq[item] = 0
freq[item] += 1
list_p = []
for key,value in freq.items():
list_p.append((key, value))
list_p = sorted(list_p, key=cmp_to_key(compare))
return list_p[-1][0]
lis = ["greenShirt", "bluePants","redShirt","blackShoes","redPants","redPants","whiteShirt","redShirt"]
print(featuredProducts(lis))
# def slowestKey(keyTimes):
#
# alphabet = 'abcdefghijklmnopqrstuvwxyz'
#
# alpha_dict = {}
# for i in range(0,len(alphabet)):
# alpha_dict[i] = alphabet[i]
#
# for i in range(len(keyTimes)-1, 0, -1):
# keyTimes[i][1] -= keyTimes[i-1][1]
#
# return alpha_dict[max(keyTimes, key = lambda x : x[1])[0]]
#
#
# print(slowestKey([[0,2],[1,3],[0,7]]))
# print(slowestKey([[0,1],[0,3],[4,5],[5,6],[4,10]]))