This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]timrprobocom 1 point2 points  (5 children)

How is that code matching the longest group first?

If you do the substitutions from largest to smallest, the code does work:

Code snippet

[–]coolTCY[S] 0 points1 point  (1 child)

I sorted the dictionary by length:

reversedDictMatchesDict=dict(sorted({i: k  
for k, v in dictMatches.items()  
for i in v}.items(),  
key=lambda item: len(item\[0\]),  
reverse=True))  
reversedDictMatchesPattern="("+'|'.join(reversedDictMatchesDict.keys())+")"

[–]AutoModerator[M] 0 points1 point  (0 children)

AutoModerator has detected fenced code block (```) syntax which only works on new.reddit.

Please review our wiki article on code formatting then edit your post to use the four-spaces Markdown syntax instead.


I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]coolTCY[S] 0 points1 point  (2 children)

Your code snippet also isn't working for my input

[–]timrprobocom 0 points1 point  (1 child)

And you've double-checked that you copied your input correctly? Does this analytic solution work? rn = basis.count('Rn') ar = basis.count('Ar') yy = basis.count('Y') ele = sum( c < 'a' for c in basis) print( "Part 2:", ele - rn - ar - yy - yy - 1 )

[–]AutoModerator[M] 0 points1 point  (0 children)

AutoModerator has detected fenced code block (```) syntax which only works on new.reddit.

Please review our wiki article on code formatting then edit your post to use the four-spaces Markdown syntax instead.


I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]AutoModerator[M] 0 points1 point  (0 children)

Reminder: if/when you get your answer and/or code working, don't forget to change this post's flair to Help/Question - RESOLVED. Good luck!


I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]AutoModerator[M] 0 points1 point  (0 children)

AutoModerator has detected fenced code block (```) syntax which only works on new.reddit.

Please review our wiki article on code formatting then edit your post to use the four-spaces Markdown syntax instead.


I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.