RUVIDEO
Поделитесь видео 🙏

Learn to program w/ Python 13. Bringing things together 영어 파이썬 코딩영어 смотреть онлайн

LC training(18:53) - Python flip between numbers We'll see if this will come up with the same one scroll down okay yeah so this is the one i had found and i actual never heard of itertools dot cycle because as i was writing my method of doing it the way i was doing it was so ugly that i was like surely there's a way and then also i was like surely there's a way to like actually like rotate so we've seen i think it was a the cue i forget which one it was that we found before that actually has a way to rotate and then you could always use like the index of zero or something like that But so coming on let's see So let's try using itertools cycle so i so looking down here you can import cycle This is just a range of two So that would calling dot next on Now with my experience i know that's not gonna work anymore but let's try let's try how to how we would actually like do that So the other option we would have is import itertools and then we could say player choice equals itertools dot cycle and then we're gonna cycle between play 1 and 2 because we can and then for i in range of let's say 10 what could we do well we could just print player choice dot next Now i already know this is not gonna be happy but let's say you get this error right and don't forget like this stuff is sublime really If we ran this in a console we would see this So i understand what this means but you might not So again you copy that error come over here paste it in Go to this first option who cares what they're doing Let's just look at this guys what he has to say ok dot next was removed in Python 3 use next iter instead right So then he says all you have to do is take dot next and then convert it to next as the built-in function that it is So let's do that So let's just say we get rid of dot next and then we print instead next player choice boom okay so that works

Summary & Code results -


경기를 하는 사람이 둘이라 했을때, player 1, 2가 번갈아 가면서 경기할 기회를 주는 것이 공평하다. 문제는 이걸 코딩으로 어떻게 기회를 주게 할 수 있느냐다. 구글링 "python flip between numbers" 해서 찾아낸 것이 itertools.cycle() 이란 메스더다. 그리고 built-in next() function도 있었다. 번갈아 가면서 차례로 경기를 할 수 있게 해주는 매직이다. 여기서 우린 iterable, iterator의 구분을 해줄 필요가 나왔다. 전자는 a thing we can iterate over 이고, 후자는 a special object with next() method 즉 next() function을 쓸 수 있게 해주는 게 iterator 라는 거다. iterator는 동시에 iterable 기능도 겸하고 있다는 것을 확인해 보았다. 더하여 iter() iterator는 reach stop iteration 기능도 한다는 것이 마냥 계속해서 반복되기만 하는 cycle iterable 기능과 대비되어 보인다.

import itertools
game = [[1, 0, 2],
[1, 1, 1],
[1, 2, 1],]
def win(current_game):
# Horizontal
for row in game:
print(row)
if row.count(row[0]) == len(row) and row[0] !=0:
print(f"player {row[0]} is the winner horizontally (-)!")
# Diagonal
diags = []
for col, row in enumerate(reversed(range(len(game)))):
diags.append(game[row][col])
if diags.count(diags[0]) == len(diags) and diags[0] !=0:
print(f"player {diags[0]} is the winner diagonally (/)!")
diags = []
for ix in range(len(game)):
diags.append(game[ix][ix])
if diags.count(diags[0]) == len(diags) and diags[0] !=0:
print(f"player {diags[0]} is the winner diagonally (\\)")
# Vertical
for col in range(len(game)):
check = []
for row in game:
check.append(row[col])
if check.count(check[0]) == len(check) and check[0] !=0:
print(f"player {check[0]} is the winner vertically (|)")
def game_board(game_map, player=0, row=0, column=0, just_display=False):
try:
if not just_display:
game_map[row][column] = player
for count, row in enumerate(game_map):
print(count, row)
return game_map
except IndexError as e:
print("Error: make sure you input row/column as 0, 1, or 2?", e)
except Exception as e:
print("Something went very wrong!", e)
play = True
players = [1, 2]
while play:
game = [[0, 0, 0],
[0, 0, 0],
[0, 0, 0]]
game_won = False
game = game_board(game, just_display=True)
player_choice = itertools.cycle([1, 2])
while not game_won:
current_player = next(player_choice)
print(f"current_player: {current_player}")
column_choice = int(input("What column do you want to play? (0, 1, 2): "))
row_choice = int(input("What row do you want to play? (0, 1, 2): "))
game = game_board(game, current_player, row_choice, column_choice)


원본 비디오: https://www.youtube.com/watch?v=au8xkSQW1kE&list=PLQVvvaa0QuDeAams7fkdcwOGBpGdHpXln&index=14

Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Learn to program w/ Python 13. Bringing things together 영어 파이썬 코딩영어» бесплатно и без регистрации, вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.

Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.

Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!

Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.