본문 바로가기

TIL

TIL 050323

skip = 'wbqd'
skip_ascii = [ord(i) for i in skip]  # [119, 98, 113, 100] / 이렇게 한 줄로 for문을 돌면서 문자열을 리스트로 만들 수 있다.

ord(): 알파벳을 아스키코드 숫자로 바꿔준다.

a: 97 ~ z: 122


from string import ascii_lowercase

atoz = ascii_lowercase
print(atoz)  # abcdefghijklmnopqrstuvwxyz


skip = 'wbqd'

temp_ascii = [chr(i) for i in range(97, 123) if chr(i) not in skip]  # 한 줄로 for문, if문, list(), chr()

# ['a', 'c', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 's', 't', 'u', 'v', 'x', 'y', 'z']

chr(): 아스키코드 숫자를 문자로


https://stackoverflow.com/questions/8951020/pythonic-circular-list

 

Pythonic Circular List

Say I have a list, l = [1, 2, 3, 4, 5, 6, 7, 8] I want to grab the index of an arbitrary element and the values of its neighbors. For example, i = l.index(n) j = l[i-1] k = l[i+1] However, for ...

stackoverflow.com

 

'TIL' 카테고리의 다른 글

TIL 050823  (0) 2023.05.09
TIL 050423  (0) 2023.05.04
TIL 050223  (0) 2023.05.02
TIL 050123  (0) 2023.05.01
TIL 042823  (0) 2023.04.28