목록계프 (6)
without haste but without rest
/* input data anne 1 3 6 4 5 6 3 5 john 3 2 3 5 7 2 peter 9 8 2 7 4 9 end */ def print_nested_dict(my_dict): for x in my_dict: if my_dict[x] == 1: print(x, end=' ') else: print('{}({})'.format(x, my_dict[x]), end=' ') print() def print_dict(my_dict): for x in my_dict: print(x, ':', end=' ', sep='') if type(my_dict[x]) == dict: print_nested_dict(my_dict[x]) else: print(my_dict[x]) def list_to_dic..
import random def make_score(a=30, b=99, dup=True): names = [chr(name) for name in range(ord('a'), ord('z'))] random.shuffle(names) if dup == True: scores = [[random.randint(a, b) for _ in range(5)] for _ in range(8)] res = list(zip(names, scores)) return res else: scores = [random.sample(range(10, 100), 5) for _ in range(8)] res = list(zip(names, scores)) return res def print_list(score_list, n..
경기 기록 import random def groups(n, j): res = [] while(True): if n - j > 0: n -= j res.append(j) else: res.append(n) break return res def make_score(n, name, count): tmp = [] for _ in range(n): scores = [random.randint(100, 180) for _ in range(count)] tmp.append(scores) res = list(zip(name, tmp)) return res def divide_group(n, total_list, group): res = [] tmp = [0] + group order = [] sum = 0 for a..
포커 import random # 스트레이트: 연속된 네개 숫자, A432나 AKQ2도 연속이라고 봄 # 숫자 부분을 'AKQJ98765432'에서의 위치로 정렬, 연속인가 검사 def strait(hand): nlist = [] for s, a in hand: nlist.append(numbers.index(a)) nlist.sort() for i in range(1, 4): if nlist[i] == 0 and nlist[i - 1] == 11: continue if nlist[i] != nlist[i - 1] + 1: return False # print(' ', nlist, end=' ') return True # 플러시: 같은 모양 네장 def flush(hand): for a in range(..
10진수, 12진수 변환 def tenToTwe(n): tempList = [] check = n while(1): letter = check % 12 check = check // 12 if letter == 10: res = 'a' elif letter == 11: res = 'b' else: res = str(letter) tempList.append(res) if check == 0: break tempList.reverse() result = ''.join(tempList) return result def tweToTen(n): tempList = list(n) resList = [] res = 0 for a in tempList: if a == 'a': temp = 10 elif a == 'b..
가장 차이가 큰 항 구하기 import random def max_value(x, y): xlist = [random.randint(x, y) for _ in range(10)] ylist = [random.randint(x, y) for _ in range(10)] res = [] print(xlist, ylist, sep='\n', end='\n\n') for i, a in enumerate(xlist): res.append(abs(a - ylist[i])) check = res.index(max(res)) for i, a in enumerate(xlist): if i == check: print("( {})".format(xlist[i]), end='\t') else: print(xlist[i], ..