Skip to content

Instantly share code, notes, and snippets.

@eliasdabbas
Last active April 16, 2024 10:03
Show Gist options
  • Save eliasdabbas/27d13d542c61884c36b826ccfb0fb47e to your computer and use it in GitHub Desktop.
Save eliasdabbas/27d13d542c61884c36b826ccfb0fb47e to your computer and use it in GitHub Desktop.
Create an HTML sitemap for a list of URLs and their anchor text
# Create anchors for all letters:
import string
print('<h3>' + '&nbsp;&nbsp;&nbsp;&nbsp;'.join([f'<a href="#{letter}">{letter}</a>' for letter in string.ascii_uppercase]) + '</h3>')
# Assuming you have a DataFrame with the columns "full_name" and "loc":
for letter in string.ascii_uppercase:
df = players_df[players_static['full_name'].str[0].eq(letter)]
print()
print(f'<div id={letter}><h2>{letter}</h2></div>')
print()
for fullname, loc in df[['full_name', 'loc']].values:
print(f'<a href="{loc}">{fullname}</a><br>')