• API
• FAQ
• Tools
• Archive
daily pastebin goal
30%
SHARE
TWEET

# Untitled

a guest Dec 14th, 2018 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. # 문제 1
2. def solution(A):
3.     dic = {}
4.     for i in A:
5.         try:
6.             dic[i] = A.count(i)
7.         except:
8.             dic[i] = 1
9.     maxkey = sorted(list(dic), key=lambda x: dic.get(x), reverse=True)[0]
10.     maxvalue = dic.get(maxkey)
11.     if maxvalue > len(dic) / 2:
12.         return A.index(maxkey)
13.     else:
14.         return -1
15.
16. # A = [3, 4, 3, 2, 3, -1, 3]
17. # solution(A)
18.
19. # 문제 2
20. def palindrome(string):
21.     ls = list(string.lower())
22.
23.     ls_alnum = []
24.     for i in ls:
25.         if i.isalnum():
26.             ls_alnum.append(i)
27.
28.     mid = len(ls_alnum) // 2
29.
30.     if len(ls_alnum) % 2:
31.         start = list(range(mid, 0, -1))
32.         end = list(range(mid+2, len(ls_alnum)+1))
33.     else:
34.         start = list(range(mid, 0, -1))
35.         end = list(range(mid+1, len(ls_alnum)+1))
36.
37.     for i, j in zip(start, end):
38.         if ls_alnum[i-1] == ls_alnum[j-1]:
39.             continue
40.         else:
41.             return False
42.
43.     return True
44.
45. # palindrome("a%Zbc!bZ&*()a")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top