This could really be anything, from any website you like. The web is full of interesting data, and if you learn a little about web-scraping, you can collect some really unique datasets.
import requests
from bs4 import BeautifulSoup
def scrape_data(url):
response = requests.get(url)
soup = BeautifulSoup(response.text, "html.parser")
games = soup.find_all("div", class_="game")
results = []
for game in games:
board = []
for row in game.find_all("div", class_="row"):
row_data = []
for cell in row.find_all("div", class_="cell"):
cell_data = cell.text.strip()
row_data.append(cell_data)
board.append(row_data)
result = game.find("div", class_="result").text.strip()
results.append((board, result))
return results
def analyze_data(results):
x_wins = 0
o_wins = 0
ties = 0
for board, result in results:
if result == "X wins":
x_wins += 1
elif result == "O wins":
o_wins += 1
else:
ties += 1
print(f"X wins: {x_wins}")
print(f"O wins: {o_wins}")
print(f"Ties: {ties}")
url = "https://www.example.com/tic-tac-toe-games"
results = scrape_data(url)
analyze_data(results)
Fundamentals
Strings
def reverse_string(string): return string[::-1] # Example usage print(reverse_string("Hello, World!")) # "!dlroW, Hello" print(reverse_string("")) # "" print(reverse_string("a")) # "a" print(reverse_string("ab")) # "ba" print(reverse_string("abc")) # "cba"
reverse_string = lambda string: string[::-1]- def reverse_string(string):
- return string[::-1]
- # Example usage
- print(reverse_string("Hello, World!")) # "!dlroW, Hello"
- print(reverse_string("")) # ""
- print(reverse_string("a")) # "a"
- print(reverse_string("ab")) # "ba"
- print(reverse_string("abc")) # "cba"