0

My goal is to slice string several time. That is, when [2,3,1] given, string 'ABCDEF' should be 'AB','CDE' and 'F'.Is there a function prepared in python for this task or How to make function with built-in functions?

    list [2,3,1] given.
    string 'ABCDEF' given,
    func('ABCDEF',[2,3,1])  --> 'AB','CDE' and 'F' 

1 Answer 1

2

If you are open to regex, one option might be:

inp = "ABCDEF"
parts = re.findall(r'(.{2})(.{3})(.)', inp)[0]
print(parts)  # ('AB', 'CDE', 'F')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.