【问题标题】:python getting index of duplicate char for a specific positionpython获取特定位置的重复字符索引
【发布时间】:2018-03-31 18:34:12
【问题描述】:

我刚刚开始使用 python。 我试图找到不止一次出现的 char 索引

这是示例字符串

08:28:57,990 DEBUG [http-0.0.0.0-18080-33] [tester] [1522412937602-580613] [TestManager] ABCD: loaded 35 test accounts

如何获取 'TestManager' 周围的 '[' 和 ']' 索引。

【问题讨论】:

标签: python indexof


【解决方案1】:

这可能会有所帮助。

s = "08:28:57,990 DEBUG [http-0.0.0.0-18080-33] [tester] [1522412937602-580613] [TestManager] ABCD: loaded 35 test accounts"
for i in reversed(s.split()):    #Split string by space and reverse the list
    if ("[" in i) and ("]" in i):                 #Check if "[" and "]" in string
        print(i)
        break

输出:

[TestManager]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-17
    • 2013-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多