2023년 1월 5일 목요일

ValueError: list.remove(x): x not in list

 파이썬을 하다가 이상한 현상이 있어 상당시간 허비하고 알게되었습니다.

from random import *
user = list(range(1,21))
shuffle(user)
second = sample(user, 4)
first = sample(second, 1)
print(first, second)
second.remove(first)
second.sort()
print('1등 당첨자 : {0}'.format(first))
print('2등 당첨자 : {0}'.format(second))

[3] [3, 5, 9, 12]

Traceback (most recent call last):

  File "/Users/gilson/eman.py", line 7, in <module>

    second.remove(first)

ValueError: list.remove(x): x not in list

구글에서 관련검색을 해봐도 적당한 답이 없네요.

결국 오류메시지 "x not in list"의 의미는 x 가 리스트가 아니어야 한다는 의미!

second.remove(first[0]) 라고 하고서야 원하는 결과를 얻게되었습니다.


댓글 없음:

tensorflow gpu 사용하기에서

 tensorflow 설치시 주의해야 한다. # Anything above 2.10 is not supported on the GPU on Windows Native python - m pip install "tensorflow<2.11...