-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhavefunhere.py
More file actions
58 lines (31 loc) · 1.26 KB
/
Copy pathhavefunhere.py
File metadata and controls
58 lines (31 loc) · 1.26 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
##### Questions comes from intenet resources #########
## start to use pycharm
## this is a test
#2019-09-06
#This is how to convert from string exppression to equation
#it is very simple just use eval() function and python will return numerical result
def eval_ (expressions):
return eval(expressions)
print eval_ ('- (3 + ( 2 - 1 ) )')
###################################################################################################
###################################################################################################
#2019-09-08
#This is a question asked by Facebook to find out the lonest, 2 unique number sequence ina list
#####################################################################################################
n = [1, 3, 5, 3, 1, 3, 1, 3]
def findSequence(seq):
y = []
finallist = []
for i in range (0, len(seq)):
for m in range (i, len(seq)):
y.append(seq[i:m])
for value in y:
length = len(set(value))
if length <= 2:
finallist.append(len(value))
else:
continue
return max(finallist)
# there are two ways to express string.
print "In this sequence, the longest sequence number is %d \n" %(findSequence (n))
print "In this sequence, the longest sequence number is {} \n".format(findSequence (n))