728x90
반응형
부분 항목 접근 : slicing (shell에서 실행하기)
[0,1,2,3,4][0:1]
[0,1,2,3,4][0:2]
[0,1,2,3,4][1:3]
[0,1,2,3,4][:3]
[0,1,2,3,4][3:]
[0,1,2,3,4][:]
[0,1,2,3,4][1:4:2]
[0,1,2,3,4][::2]
리스트 주요 함수 : len, sort, reverse, random, shuffle (shell에서 실행하기)
import numpy as np
np.random.seed(42)
iList=[*np.random.randint(0,100,5)]
iList
len(iList)
iList.sort()
iList
import random
random.shuffle(iList)
iList
임의 숫자 생성 : random.random(), random.randint(a,b) (shell에서 실행하기)
import random
fList=[]
for _ in range(5):
fList.append(random.random())
fList
iList=[]
for _ in range(5):
iList.append(random.randint(0,100))
iList
임의 문자열 생성 : random.choices() (shell에서 실행하기)
1.
import random
import string
string.ascii_letters
''.join(random.choices(string.ascii_letters,k=10))
2.
import random
import string
sList=[]
for _ in range(5):
s=''.join(random.choices(string.ascii_letters,k=8))
sList.append(s)
sList
3.
import random
import string
[''.join(random.choices(string.ascii_letters,k=8)) for _ in range(5)]
sList2=[''.join(random.choices(string.ascii_letters,k=8))for _ in range(5)]
sList2
임의 문자열 생성 2 : numpy.random.random(), numpy.random.randint() (shell에서 실행하기)
import numpy as np
np.random.random(5)
list(np.random.random(5))
[*np.random.random(5)]
np.random.randint(0,100,5)
list(np.random.randint(0,100,5))
[*np.random.randint(0,100,5)]
728x90
반응형
'즐거운프로그래밍' 카테고리의 다른 글
[파이썬] 기초 다지기 dict(딕셔너리 함수) (0) | 2023.10.27 |
---|---|
[파이썬] 기초 다지기 tuple, dict, set와 packing operator (0) | 2023.10.27 |
[파이썬] 기초 다지기 while 문 (0) | 2023.10.27 |
[파이썬] 기초 다지기 if 문 (1) | 2023.10.27 |
[파이썬] 기초 다지기 예제 3 (0) | 2023.10.27 |