제로베이스 데이터 취업 스쿨 - 22일차(6/23)

수야·2023년 6월 23일
0

리스트 나머지 기능들

리스트도 곱셈 연산이 가능하다! 특정 아이템의 인덱스를 찾자

실습


import  random
sampleList = random.sample(range(1,11),10)
selectIndex = int(input('숫자 7의 위치 입력'))
searchIndec = sampleList.index(7)
if selectIndex == searchIndec:
    print('정답')
else:
    print('오답')

리스트 나머지 기능들(2)


실습

import random
types = ['A', 'B', 'O', 'AB']
todayData = []
typeCnt=[]
for i in range(100):
    type = types[random.randrange(len(types))]
    todayData.append(type)


print(f'today num : {len(todayData)}')

for type in types :
    print(f'{type} \t : {todayData.count(type)}')

튜플

리스트와 비슷하지만 아이템 변경 불가

실습

튜플 아이템 조회


실습

in과 not in 키워드

아이템 존재 유무 판단하기

실습

import random

ranInt = random.sample(range(1,11), 5)
check = int(input('숫자 입력'))
result = True
while result == True:
    if check in ranInt :
        print('있다')
        result =False
        print(ranInt)
    else:
        print('없다')
        continue

실습


wrongWord = ['쩔었다','짭새','꼽사리','먹튀','지린','쪼개다','뒷담 까다',]
sentence = '짭새 등장에 강도들은 모두 쩔었다. 그리고 당도 들은 지린 듯 도망갔다.'
for word in wrongWord :
    if word in sentence :
        print(f'비속어 : {word}')

튜플 길이

실습

튜플 결합


실습

myNum = (11,2,3,4,5,6,7,8,)
friendNum = (1,2,3,4,5,6,7,8,9,10)
print(myNum)
print(friendNum)
for number in myNum :
    if number not in friendNum :
        friendNum = friendNum + (number, )

print(friendNum)

튜플 슬라이싱

원하는 아이템만 뽑아내자!




profile
수야는 코린이에서 더 나아갈거야

0개의 댓글