Skip to content

Instantly share code, notes, and snippets.

View shoark7's full-sized avatar
🎯
Focusing on being better

Sunghwan Park shoark7

🎯
Focusing on being better
View GitHub Profile
@shoark7
shoark7 / gist:f061be65c98b8a2332ca97753c20215b
Created September 29, 2016 13:10
Get a sum of divisors of a natural number, n
"""
Our plan now is to get a sum of divisors of a natural number, n.
For example , let's say n is 12. 12 = (2**2) * (3**1),
Formula to get a sum of divisors of 12 is (2**0 + 2**1 + 2**2) * (3**0 + 3**1) = 28.
Divisors of 12 is [1, 2, 3, 4, 6, 12, ], so the formula is right.
We realize this algorithm.
Start date = 2016/09/29
End date = 2016/09/29
"""
@shoark7
shoark7 / list_prettify161213.py
Last active December 13, 2016 02:55
List prettify :)
"""
List prettify function proposed by "파이썬초짜" in my kakao open chatting room.
"""
import random
import string
sample_list = [random.choice(string.ascii_lowercase) * random.randint(4, 10) for _ in range(40)]
def list_prettify(input_list, align=False):
if align:
@shoark7
shoark7 / get_divide_sum.py
Last active December 30, 2016 05:30
Question by "λ„μ™€μ£Όμ„Έμš”" in Kakao python chatting room.
def get_sum():
number = int(input('숫자λ₯Ό μž…λ ₯ν•΄μ£Όμ„Έμš” : '))
rt_value = 1
rt_string = '1'
for i in range(2, number + 1):
rt_value += 1 / i
rt_string += ' + 1/{}'.format(i)
rt_string += ' = {}'.format(rt_value)
print(rt_string)
@shoark7
shoark7 / prime_number_count.py
Created November 25, 2017 02:21
This file contains functions to calculate how many prime numbers exist in a list.
"""μ£Όμ–΄μ§„ μ •μˆ˜ λ¦¬μŠ€νŠΈμ—μ„œ μ •μˆ˜μ˜ 개수λ₯Ό μ„Έμ„œ 좜λ ₯ν•˜λŠ” ν•¨μˆ˜
이 ν•¨μˆ˜μ˜ νŠΉμ§•μ€ λ‹€μŒκ³Ό κ°™μ•„.
ν”„λ‘œκ·Έλž˜λ°μ—μ„œ λͺ¨λ“ˆμ„±μ€ κ½€λ‚˜ μ€‘μš”ν•œ κ°œλ…μ΄μ•Ό. 그게 뭐냐면
μ‰½κ²Œ λ§ν•˜λ©΄ μ—¬κΈ°μ„œ μ“΄ κΈ°λŠ₯을 κ·Έλž˜λ„ 뚝 λ–Όκ°€μ„œ
λ‹€λ₯Έ 곳에 λΆ™μ˜€μ„ λ•Œλ„ μ˜¨μ „νžˆ μž‘λ™ν• κΉŒμ— λŒ€ν•΄ κ³ λ―Όν•˜λŠ” κ±°μž„.
μ™œλƒν•˜λ©΄ 싀무에선 이전 κΈ°λŠ₯을 μ½”λ”© λ³΅λΆ™ν•΄μ„œ μ“°λŠ” κ²½μš°κ°€ κ½€ λ§Žκ±°λ“ .
λ³΄μ…ˆ. λ„ˆμ˜ ν•¨μˆ˜λŠ” 크게 두 κ°€μ§€ κΈ°λŠ₯이 있음.
@shoark7
shoark7 / zero_fill.py
Last active December 14, 2017 13:31
Implement str.zfill method as function
def is_integer(n):
"""Return True if given n is integer.
Difference with isinstance(n, int) is that
this function returns True for string instance '123'.
"""
try:
int(n)
except:
return False
@shoark7
shoark7 / fibonacci_collections.py
Created September 9, 2018 09:22
I show you ways to implement fibonacci algorithms
# ν”Όλ³΄λ‚˜μΉ˜λ₯Ό ν•΄κ²°ν•˜λŠ” 5κ°€μ§€ 방법을 μ†Œκ°œν•©λ‹ˆλ‹€.
# λͺ¨λ“  μž…λ ₯은 0 μ΄μƒμ˜ μ •μˆ˜λΌκ³  κ°€μ •ν•©λ‹ˆλ‹€.
#1. κ°€μž₯ 일반적인 식, λ³΅μž‘λ„λŠ” O(2 ** n)
def fibonacci(n):
return fibonacci(n-1) + fibonacci(n-2) if n >= 2 else n
def iterate(a, b, c):
l = [a, b, c]
l = [n if n else 1 for n in l]
def find(chosen, got):
if got == 3:
print(''.join(chosen))
return
for i in range(l[got]):
chosen.append(str(i))
find(chosen, got+1)
@shoark7
shoark7 / newsbigdata_api_example.py
Last active April 17, 2019 08:53
It's for Joohyung
"""μ½”λ“œ μ‹€ν–‰ν•˜κΈ° 전에 λ„ˆκ°€ μž‘μ—…ν•˜λŠ” ν™˜κ²½μ—μ„œ CMD에(μœˆλ„μš° μ“°μ§€?)
pip3 install requests
라고 μž…λ ₯ν•΄μ„œ 이 λͺ¨λ“ˆμ„ λ‹€μš΄ λ°›μ•„. ꡉμž₯히 유λͺ…ν•˜κ³ , urllib μ΄λŸ°κ±°λ³΄λ‹€ μ‚¬μš©μ„±μ΄ 훨씬 μ’‹μ•„.
"""
import json
import requests # λͺ¨λ“ˆλͺ…은 abc μˆœμ„œλŒ€λ‘œ μ°¨λ‘€λ‘œ 적고,
KEY = 'λ„ˆμ˜λ°”λ‘œκ·Έν‚€ν‚€λŠ”μ°¨μ—΄μ‡ λ₯Όλ‚˜νƒ€λ‚΄κΈ°λ„ν•˜μ§€'
@shoark7
shoark7 / python-print-advanced.md
Created June 12, 2019 11:30
Python의 print ν•¨μˆ˜μ— λŒ€ν•΄ 쒀더 μ•Œμ•„λ΄…λ‹ˆλ‹€.

λ¨Όμ € μ˜€λŠ˜λ„ 고생 λ§ŽμœΌμ…¨μŠ΅λ‹ˆλ‹€.

였늘 λ“£κ²Œ λ˜μ‹œλŠ” λ‚΄μš©μ€ 거의 λͺ¨λ“  μ–Έμ–΄μ—μ„œ 처음 배우기 마련인 좜λ ₯에 λŒ€ν•œ ν•¨μˆ˜μž…λ‹ˆλ‹€. νŒŒμ΄μ¬μ—μ„œλŠ” λŒ€ν‘œμ μœΌλ‘œ printλ₯Ό 배우게 λ˜λŠ”λ°μš”. 이 printλΌλŠ” ν•¨μˆ˜μ— λŒ€ν•΄ 보닀 μ‹¬ν™”λœ λ‚΄μš©μ„ μ†Œκ°œλ“œλ¦¬λ €κ³  ν•©λ‹ˆλ‹€.

λ¨Όμ € μ‹œμž‘μ— μ•žμ„œ λ‹€μŒκ³Ό 같이 μž…λ ₯ν•΄λ³΄κ² μŠ΅λ‹ˆλ‹€.

help(print)
@shoark7
shoark7 / python-print-advanced.md
Last active November 8, 2022 08:39
Python의 print ν•¨μˆ˜μ— λŒ€ν•΄ 쒀더 μ•Œμ•„λ΄…λ‹ˆλ‹€.

λ¨Όμ € μ˜€λŠ˜λ„ 고생 λ§ŽμœΌμ…¨μŠ΅λ‹ˆλ‹€.

였늘 λ“€μœΌμ‹  λ‚΄μš©μ€ 거의 λͺ¨λ“  μ–Έμ–΄μ—μ„œ 처음 배우기 마련인 좜λ ₯에 λŒ€ν•œ ν•¨μˆ˜μž…λ‹ˆλ‹€. νŒŒμ΄μ¬μ—μ„œλŠ” λŒ€ν‘œμ μœΌλ‘œ printλ₯Ό 배우게 λ˜λŠ”λ°μš”. 이 printλΌλŠ” ν•¨μˆ˜μ— λŒ€ν•΄ 보닀 μ‹¬ν™”λœ λ‚΄μš©μ„ μ†Œκ°œλ“œλ¦¬λ €κ³  ν•©λ‹ˆλ‹€.

λ¨Όμ € μ‹œμž‘μ— μ•žμ„œ λ‹€μŒκ³Ό 같이 μž…λ ₯ν•΄λ³΄κ² μŠ΅λ‹ˆλ‹€.

help(print)