小编Jon*_*Lee的帖子

Python 字符串列表中的子字符串列表

我想查找列表中是否包含子字符串列表。例如,我有:

    string_list = ['item1', 'item2', 'subject3', 'subject4']
Run Code Online (Sandbox Code Playgroud)

和子串列表

    substrings = ['item', 'subject']
Run Code Online (Sandbox Code Playgroud)

我想查找 string_list 的任何项目中是否包含“item”或“subject”。就个人而言,我会做类似的事情:

    any('item' in x for x in string_list)
Run Code Online (Sandbox Code Playgroud)

这适用于一个子字符串,但我想找到一种在子字符串列表中搜索两个字符串的漂亮方法。

python substring list

6
推荐指数
1
解决办法
2728
查看次数

查找列中的更改索引

有没有办法在R列中找到因子变化指数?例如:

x <- c("aaa", "aaa", "aaa", "bbb", "bbb", "ccc", "ddd")
Run Code Online (Sandbox Code Playgroud)

将返回3,5,6

r

5
推荐指数
3
解决办法
768
查看次数

在python字符串中插入连字符

我正在抓一个列表,但想将字符串转换为永久链接,每个单词之间都有连字符.

例如,我有一个列表:

['hi there', 'help please','with my problem']
Run Code Online (Sandbox Code Playgroud)

我希望它最终像:

['hi-there','help-please', 'with-my-problem']
Run Code Online (Sandbox Code Playgroud)

最好的方法是什么?

python string hyperlink hyphen

0
推荐指数
1
解决办法
5414
查看次数

标签 统计

python ×2

hyperlink ×1

hyphen ×1

list ×1

r ×1

string ×1

substring ×1