Skip to content
Advertisement

Python Challenge level 3 – Solving with string slicing

apologies to posting the question, as has been answered in other questions as well. However, couldn’t figure out what’s wrong with this solution. The question requires to find the lower-cased characters bordered by 3 upper-cased characters on each side. The code i’ve writting:

JavaScript

The string i’m getting is

‘lgvcaaginbkvsoezhtlnldslyitlooqfgiksudtm’ vs ‘linkedlist’

Thanks for the help.

Edit: for some reason the following code seems to work:

JavaScript

Advertisement

Answer

What you are trying to do is match a pattern : Not Upper, Upper, Upper, Upper, Not Upper, Upper, Upper, Upper, Not Upper. This is easier to catch if you use a signature for your string:

JavaScript

You are looking for the lUUUlUUUl substrings in the sig string. Python has no builtin for findall, but you can to iterate over the results of find:

JavaScript

You may also use re.finditer with a regex pattern, but is more complicated.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement