# 영문 대/소문자를 소/대문자로 변환
# input: 입력된 문자열data, result: 대/소문자 변환결과

def change(input):
   result = ""
   for st in input:
        if(st.isupper()):
               result = result + str.lower()
        else :
               result = result + str.upper()

 

    return result

 

 

 

# 주어진 사다리 정보를 이용하여 시작 번호에 대한 결과 번호를 구하기 

# ladder: 사다리정보, start: 시작번호, result: 결과번호

def ResultNo(ladder, start):
    result = 0

 

    cur = start 
    for line in ladder:
        if line[0] == cur:
            cur = line[1]
        elif line[1] == cur:
            cur = line[0]
    result = cur

    return result

 

 

 

# 입력된 7~9자리 숫자열 뒤부터 3자리씩 끊어서 3자리 숫자로만들고 큰숫자순으로 정렬하기

input: 입력된 숫자열, 숫자로된 문자열data, result: 정열된 숫자열, 숫자로된 문자열 목록

def sortNum(input):
    sortedNum = []

    inp = input
    n1, n2, n3 = int(inp[-3:]), int(inp[-6:-3]), int(inp[-9:-6])

    if n3 < 10 :
        n3 = int(str(n3) + "12")
    elif n3 >=10 and n3 < 100 :
        n3 = int(str(n3) + "1")
    n = [n1, n2, n3]
    n = sorted(n, reverse=True)
    sortedNum = n

    return sortedNum

 

 

 

# 정열된 3자리 숫자를 자릿수끼리 덧셈 연산결과를 이용 새로운 숫자 만들기

sortedNum: 정열된 숫자열, 숫자로된 문자열 목록, result: 생성된 숫자

def NewNum(sortedNum):
    NewNum = 0
     
    res = []
    qor = [int(str(item)[0]) for item in sortedNum]
    tlq = [int(str(item)[1]) for item in sortedNum]
    dlf = [int(str(item)[2]) for item in sortedNum]
    res.append(sum(qor) % 10)
    res.append(sum(tlq) % 10)
    res.append(sum(dlf) % 10)

    for i in range(len(res)):
        NewNumber += 10**(len(res) - i - 1) * res[i]

    return int(NewNumber)

 

[예제 사이트]

1. 100 개 이상의 실습이 포함 된 대화식 Python 3 튜토리얼 - Snakify

https://snakify.org/ko/

 

Snakify - Python 3 Interactive Course

The online course for beginners with more than 100 problems that turn you into a developer.

snakify.org

2. Active State

http://code.activestate.com/recipes/langs/python/

# 문자열 대소문자 변환 
s="King Dom" 

import string 
print(s.title())                    ## 문장의 첫글자만 대문자로 
print(s.capitalize())             ## 단어별 첫글자를 대문자로 
print(string.capwords(s))      ## split 한 후 단어별 첫글자를 대문자로 변경후 join 

 



# 알파벳/숫자 구별 

string.upper()       → 대문자로 변환

string.lower()       → 소문자로 변환

string.swapcase()  → 대문자 ▷ 소문자, 대문자 ▷ 소문자로 변환

string.capitalize()  → 첫문자를 대문자로 변환

string.title()         → 단어의 첫문자를 대문자로 변환

 

string.isalpha()    --> true/false

 

 

## 문자열 분리 
>>> b = a.split() 
>>> b 
['True', 'love', 'is', 'hard', 'to', 'find', 'now'] 



# 문자열 합치기  
>>> ''.join(b) 
'Trueloveishardtofindnow' 
>>> ' '.join(b) 
'True love is hard to find now' 

 

 


## 문자열 치환
import re
text = u'010-1566#7152'
parse = re.sub('[-=.#/?:$}]', '', text)
print parse


 

# List 생성  
>>> a = "True love is hard to find now" 
>>> a.split() 
['True', 'love', 'is', 'hard', 'to', 'find', 'now'] 

#List 길이 구하기  
>>> len(b) 
7
 
# List 마지막 항목 출력  
>>> b[-1] 
'now' 

 

 


# 숫자, 문자 혼합된 리스트에서 문자열 제거 
    for txt in inList :
        try :
            newList.append(int(txt))
        except :
            continue

 



## 집합 ↔ 리스트 
>>> a=[1,1,2,2,3,3,4,4,5,5]
>>> b=set(a)
>>> b
{1, 2, 3, 4, 5}

>>> c=list(b)
>>> c
[1, 2, 3, 4, 5]



## 딕셔너리 
student={"이름":"로바이"}
student["나이"]=30
list(student.keys())
["이름","나이"]

list(student.values())
["로바이",30]
 


## List 정렬 
>>> a=[1,3,4,5,2]
>>> a.sort()
>>> a
[1,2,3,4,5]

>>> a.reverse()
[5,4,3,2,1]

>>> a[::-1]
[5, 4, 3, 2, 1]



## List 정렬2 (2개 리스트를 한개의 순서에 맞추어 동시에 정렬)
for i in range (0, len(totalID)-1) :
     for k in range(i+1, len(totalID)) :
         if int(totalPay[i]) < int(totalPay[k]) :
             totalPay[i], totalPay[k] = totalPay[k], totalPay[i]
             totalID[i], totalID[k] = totalID[k], totalID[i]

 


## List append 
retList.append([totalID[0], totalPay[0], grade])

## List index 
    for i in range(0,len(userID)) :
        uid = userID[i]
        upay = userPay[i]
        if uid in totalID :
            idx = totalID.index(uid)
            totalPay[idx] += upay
        else :
            totalID.append(uid)
            totalPay.append(upay)



## dictionary 정렬 
import operator
trainlist = sorted(dic.items(), key=operator.itemgetter(1), reverse=True) 
  
  
 
## 변환
숫자를 문자로(ASCii code → 문자) :  chr()
문자를 숫자로(문자 → ASCii code) : ord()

chr(ord(tmp1) +1)

 

 

[Python 문자열 함수 정리]

https://simplesolace.tistory.com/entry/%ED%8C%8C%EC%9D%B4%EC%8D%AC-python-%EB%AC%B8%EC%9E%90%EC%97%B4

 

 

[파이썬] python 문자열 함수정리

이 문서는 파이썬 2점대를 기준으로 작성되었습니다. 4장 문자열 [문자열 대치 기능] >>>import string t = string.Template('$page: $title') t.substitute({'page':2, 'title' : 'The Best of Times'}) t.safe_s..

simplesolace.tistory.com

 

1. 실행(Run)

   현재소스 실행     : Ctrl + Shift + F10

   최근소스 재실행  : Shift + F10

   소스선택 실행     : Alt + Shift + F10


2. 편집

   수정취소/되돌리기(Undo)   : Ctrl + z

   수정취소 재실행(Redo)      : Ctrl + Shift + z

   현재라인 위/아래 라인으로이동      : Alt + ↑ 또는 Alt + ↓


   최근 실행파일 열기      : Ctrl + e

   파일 열기                  : Ctrl + Shift + n, Ctrl + n

   파일간 이동               : Alt + ← 또는 Alt + →

 

   선택내역 복제    : Ctrl + d (Shift로 선택후 실행시 전체, 미선택시 1줄 복제)

   블럭단위 선택    : Ctrl + w

   삭제        : Crtl + y

   복사        : Ctrl + c

   붙여넣기   : Ctrl + v


   ( )소괄호 밖 탈출     : Ctrl + Shift + Enter

   주석처리(#)            : Ctrl + /(영역선택후)

   글자 이동(Tab간격)  : 순방향: Tab, 역방향 : Shift + Tab(영역선택후)   

   전체화면 이동         : Ctrl + 방향키


3. 기타

   소스(탭)간 이동        : Alt + 좌/우방향키 Ctrl + Tab (2개탭사이만 이동)

   폴더, 새파일 생성     : Alt + Insert

   폴더, 파일이름 변경  : Shift + F6

   파일 목록열기         : Ctrl + e


   편집창 닫기            : Ctrl + F4

   파이참 종료            :  Alt + F4


4. Debugging

   Break point

   한줄씩 실행     : F8

   함수로 이동     : F7

   run to cursor   : Run


※ Run수행시 오류발생할때 조치 사항

File ▷ Setting ▷ Project : Python ▷ Project Interpreter 선택 (package, version, "latest Version"내용이 보여야 정상임)

▶우측의 상단의 클릭  ▷ python.exe 선택 ▷ ok ▷ apply후 "Project Interpreter"의 상태 확인 

 

 

1.점프투 파이썬 정규표현식

https://wikidocs.net/4309

 

 

Ⅰ. 인터넷 서적

1.왕초보를 위한 Python 2.7

https://wikidocs.net/book/2

 

3. 파이썬 - 기본을 갈고 닦자!

https://wikidocs.net/book/1553

 

3.점프 투 파이썬

https://wikidocs.net/book/1

 

4.파이썬으로 배우는 알고리즘 트레이딩

https://wikidocs.net/book/110

 

5. "A Byte of Python"

http://byteofpython-korean.sourceforge.net/byte_of_python.html

 

6. 예제로 배우는 파이썬 프로그래밍

http://pythonstudy.xyz/Python/Basics

 

 

Ⅱ. 참고사이트

1. 코딩사이트

1) 생활코딩

https://opentutorials.org/course/1750


2) 코드워

https://www.codewars.com/


3)해쉬코드-개발자를 위한 Q&A 및 코드실행

http://hashcode.co.kr/ 

 

2. 인터넷자료

https://076923.github.io/posts/#python

+ Recent posts