Skip to content

Conversation

@nxnode
Copy link
Owner

@nxnode nxnode commented Apr 3, 2024

No description provided.

Comment on lines +5 to +10
position_index = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
positions = ""
for character in characters:
if character.isalpha():
positions += f"{position_index.index(character) + 1} "
return positions.rstrip()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't readily see how the spaces are being added to positions?

The .index(character) method isn't very efficient, it has to look through the whole list to find the index. Since it has to be written out anyway, you might use a dict like {"a": 1, "b": 2...}. The lookup would then be o(1) instead of needing to search the whole alphabet each time.

There is probably also a way to use the built in ord method on the lower letter and some math to get the number.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see f"{position_index.index(character) + 1} " has a space at the end that is then trimmed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants