一个打印字符串部分的迭代器

huangapple go评论103阅读模式
英文:

An iterator that prints part of a string

问题

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
我用黑色标记了我需要叙述者运行和打印的部分。

英文:

一个打印字符串部分的迭代器

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

答案1

得分: 1

你可以使用两个分割,一个在 - 处,另一个在 ,

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('-')]

英文:

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('-')]

答案2

得分: 0

你已经差不多完成了。在你的第一个split命令之后,duration是一个字符串列表。

然后,你遍历这些字符串,在每个字符串上调用split,但是用,代替-

英文:

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 -.

huangapple
  • 本文由 发表于 2020年1月7日 00:13:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/59615394.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定