Python Basic Exec2

JeyS·2020년 6월 3일

Python Exec

목록 보기
2/3
a={"one":1, "two":2, "three":3}
a["one"]
a={"a":1, "b":3, "c":5, "d":7}
b=[(x, a[x]) for x in a]
b
a는 dictionary(dic)니깐 변수값 x는 a dic의 key값만
가지게(가질수있게) 된다!? 

고로 x에는 "a","b"등의 key만 오게되고 a\[x\] 에는 
a dic의 key인 "a"가 오며 표현하면 a\["a"\]는 
즉, value 값인 1이 나오게 된다!
l="""Batman.The.Animated.Series.S01E01."""
l2="1080p.BluRay.DTSHD-MA.H.264-BTN"
l3="i like programming, i "
a="Batman.The.Animated.Series.S01E01.The.Cat.and.the.Claw.Part.One.1080p.BluRay.DTSHD-MA.H.264-BTN"

print(a[0:7])
print(len(l),len(l2),len(l3))
print(a.strip('.'))
Batman.The.Animated.Series.S01E01.The.Cat.and.the.Claw.Part.One.1080p.BluRay.DTSHD-MA.H.264-BTN  
Batman The Animated Series 15 - The Cat and the Claw

옵션에서 '.'' '(스페이스)를 없는셈치고 비교하는 연산을 하면  
좋을텐데.. 어떻게 할수있을까? - 밑에답!
l4="i like programming, i like swimming."
a="abcabcabc"
b="abcabcabc2"
c="abcabc"
print(l4.find('like'))
print(l4.rfind('like'))
print(l4.index('like'))
print(l4.rindex('like'))
print(l4.startswith('progr', 7)) # 7번째 문자열이 progr로 시작하는가?
print(l4.endswith('swimming.', 0, 99))# 0부터 26번째 위치 사이의 문자열이 like로 끝나는가?
if c.startswith(a):
    print(c.startswith(a))
else:
    print(c.startswith(a))    
print('<>abc<><><>'.strip('<>'))    # 특정 문자열 제거 좌우로만
u = '  spam and ham    '
print(u.replace(' ',''))    # replace를 이용한 특정 문자열 제거, 공백 제거 
t = u.split()
print(''.join(t))           # split후 join을 이용한 '' 공백 제거
print(':'.join(t))          # ':' 문자로 결합
print ('\n'.join(t))        # 줄 바꾸기로 결합
import re
text = u'010-1566#7152'
parse = re.sub('[-=.#/?:$}]', '', text) # 정규 표현식을 이용한 문자 치환,제거
print (parse)
print(u'\u4000\u4001abc\u4000'.strip(u'\u4000'))
s="  #$     abc.CBA.abc  #$% &"
print(s.replace('#$','%').replace('%',''))
ss=re.sub('[ #$%&.]','', s)
ss=re.sub('cba','jjj',re.sub('abc','cba', ss))
print(ss)
s='abcCBAdef'
a=s[3:-3]
print(a in s)
print(s,a,b)
import os         #list내 반복,조건문 표현. 코드가 축약된다.
import re
path = "L:\ANI\Batman The Animated Series"
flist = os.listdir(path)
flistmkv = [file for file in flist if file.endswith('.mkv')]
flistre = [file.replace('.','') for file in flistmkv]

pathsub = "D:\Downloads\Subtiltle relation\Batman+The+Animated+Series"
sublist = os.listdir(pathsub)
subre = [file.replace(' ', '') for file in sublist]

print(subre)
import os
import re
path = "L:\ANI\Batman The Animated Series"
pathsub = "D:\Downloads\Subtiltle relation\Batman+The+Animated+Series"
flist = os.listdir(path)
sublist = os.listdir(pathsub)
#flistmkv = []
flistre = []
subre = []
for i in flist:
    if i.endswith('.mkv'):
        #i=i.replace('.', '')    #replace함수를 이용한 문자열 치환
        i=re.sub('[ .]', '', i)  #re.sub을 활용한 문자열 치환, 변환된 객체는 재대입해야함(i=i)
        i=i[29:-30]
        flistre.append(i)


print(flistre)
f=open("aaa.txt", 'w')
f.write('ddddddjjjjjj')
f.close()
print (f)
f=open("aaa.txt")       # defalt 'r' mode는
for file in f:          # for문에서 변수로 한라인식 반환하는 듯하다.
    print(file)
print(f)
a= "'"
print (a)
a="Two face Part One Part Two.smi"
b=a.replace('PartTwo', 'PartII')
c=re.sub('PartTwo','PartII',a)
f = a.replace(' ','').replace('.', '').replace('PartTwo','PartII').replace('PartOne','')
print(a)
print(b)
print(c)
print(f)
a="Batman.The.Animated.Series.S01E58.The.Demons.Quest.Part.Two.1080p.BluRay.DTSHD-MA.H.264-BTN.mkv"
b="Batman.The.Animated.Series.S01E51.Robins.Reckoning.Part.One.1080p.BluRay.DTSHD-MA.H.264-BTN.mkv"
c="Batman The Animated Series 10 - Two Face Part I.smi"
d=a.replace('[.-]','')  # 문자 동시 변환은 안되는듯 re.sub써야할듯하다.
print(a[34:-35])
print(b[34:-35])
print(c[32:-4])
print(d)

0개의 댓글