作者:安份丶小娚人 | 来源:互联网 | 2024-09-29 17:33
This question already has an answer here:
这个问题在这里已有答案:
- Iterate a list as pair (current, next) in Python 8 answers
- 在Python 8答案中将列表作为对(当前,下一个)进行迭代
Very simple problem, although I am having quite a tough time solving it.
很简单的问题,虽然我很难解决它。
Take a look at the code and I will explain below:
看看代码,我将在下面解释:
def printc(some_text):
split_text = list(some_text)
for x in split_text:
if x is '{'
# this is what i need help with
printc("{CCyan, {RRed, {YYello)
The idea behind this and it is still very early in the code development, but what I am trying to do is create an iterator that searches through "split_text" and finds the character '{' then i want to test what character is situated right next to it. How would i go about doing that?
这背后的想法,它仍然是代码开发的早期,但我想要做的是创建一个迭代器,搜索“split_text”并找到字符'{'然后我想测试下一个字符是什么它。我该怎么做呢?
For example is searches through split_text and finds the first { i want to see if the character next to it is either A, B, C, etc...
例如,通过split_text搜索并找到第一个{我想看看它旁边的字符是A,B,C等...
Any ideas?
有任何想法吗?
3 个解决方案