Skip to content

Instantly share code, notes, and snippets.

@ncalm
Created April 7, 2023 14:10
Show Gist options
  • Select an option

  • Save ncalm/f26b3ed2bd5f0de3b9020c2978057fa0 to your computer and use it in GitHub Desktop.

Select an option

Save ncalm/f26b3ed2bd5f0de3b9020c2978057fa0 to your computer and use it in GitHub Desktop.
Python solution to Excel challenge 168
import pandas as pd
# Original link: https://onedrive.live.com/view.aspx?resid=E11B26EEAACB7947!8211&ithint=file%2cxlsx&authkey=!ABt7knDc8bHLlFU
problem_url = 'https://onedrive.live.com/download?resid=E11B26EEAACB7947!8211&ithint=file%2cxlsx&authkey=!ABt7knDc8bHLlFU'
df = pd.read_excel(problem_url, sheet_name = 'Sheet1')
# Get the indices of the capital letters
# list(w) splits each word into characters
# enumerate lets us loop through each element c in its list parameter and provides an index i
cap_indices = [
[str(i+1) for i, c in enumerate(list(w)) if c.isupper()]
for w in df.Words
]
# Join the indices
result = ['-'.join(c) for c in cap_indices]
result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment