Spaces To String List

Asked By 5 points N/A Posted on -
qa-featured

I have the chain and the board. Strings have the same number of letters as arrays. I have to divide s to create a list that has the same length as each element.

s = ‘Python programming language’

arr = [‘lkjhgf’, ‘zx’, ‘qw’, ‘ertyuiopakk’, ‘foacdhlc’]

How can I get my expected result?

SHARE
Answered By 0 points N/A #318483

Spaces To String List

qa-featured

It is much cleaner to use iter with next:

s = ‘pythonisan programming language’

arr = [‘lkjhgf’, ‘zx’, ‘qw’, ‘ertyuiopakk’, ‘foacdhlc’]

new_s = iter (s)

result = [” .join (next (new_s) for _ in i) for i in arr]

Output:

[‘Python’, ‘is’, ‘one’, ‘programming’, ‘language’]

Login/Register to Answer

Related Questions