saar
saar

Reputation: 27

An iterator that prints part of a string

enter image description here

I want to create an iterator to run and print all the parts with the numbers, how do I access them? I marked in black what I needed the narrator to run and print

Upvotes: 1

Views: 55

Answers (2)

tenhjo
tenhjo

Reputation: 4537

You can use two splits, one at - and one at ,

notes = 'sol,250-mi,250-mi,500-fa,250-re,250-re,500-do,250-re,250-mi,250-fa,250'
numbers = [temp.split(',')[1] for temp in notes.split('-')]

Upvotes: 1

cadolphs
cadolphs

Reputation: 9647

You're pretty much there already. After your first split command, duration is a list of strings.

Then you iterate over those strings and on each of those you call split again, but with , instead of -.

Upvotes: 0

Related Questions