junxiaosong / AlphaZero_Gomoku

An implementation of the AlphaZero algorithm for Gomoku (also called Gobang or Five in a Row)
MIT License
3.33k stars 970 forks source link

"play_data = list(play_data)[:]" vs "play_data = list(play_data)" #87

Open IanFan opened 5 years ago

IanFan commented 5 years ago

play_data = list(play_data)[:] vs play_data = list(play_data) python2.7: list(play_data)[:] is fine python3.6: list(play_data)[:] is []

apocalypse-revelation commented 4 years ago

用这个[]赋值有点深拷贝的意思

junxiaosong commented 4 years ago

play_data = list(play_data)[:] vs play_data = list(play_data) python2.7: list(play_data)[:] is fine python3.6: list(play_data)[:] is []

It's nothing to do with the [:] operator. play_data is an zip, which returns an iterator in Python 3. You can only iterate over an iterator once. So you get [] if you call list(play_data) the second time. For example:

aa = zip([1,2,3],[3,4,5])
list(aa)
>>> [(1, 3), (2, 4), (3, 5)]
list(aa)
>>> []