Skip to content

Commit c098a4e

Browse files
committed
Update 626. Exchange Seats.py
1 parent 12d6e1f commit c098a4e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import pandas as pd
2+
3+
def exchange_seats(seat: pd.DataFrame) -> pd.DataFrame:
4+
# Total number of students
5+
total = seat.shape[0]
6+
7+
# Function to compute the new seat id
8+
def new_id(row):
9+
# For odd id values:
10+
if row['id'] % 2 != 0:
11+
# If it's the last row in an odd-length list, do not change the id.
12+
if row['id'] == total:
13+
return row['id']
14+
else:
15+
return row['id'] + 1
16+
# For even id values, swap with previous odd id
17+
else:
18+
return row['id'] - 1

0 commit comments

Comments
 (0)