社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  erhesto  »  全部回复
回复总数  2
6 年前
回复了 erhesto 创建的主题 » 是否有一个python函数从唯一值获取所有索引?

不知道任何预先构建的解决方案,可能需要创建自己的解决方案。这有不同的方法,但是使用经典的Python实现,您可以轻松地创建count_dict并从原始列表中筛选count为1的值。

>>> from collections import Counter
>>> example = [0,1,1,2,3,3,4]
>>> counted = Counter(example)
>>> desired_index_list = [index for index, elem in enumerate(example) if counted[elem] == 1]
>>> desired_index_list
[0, 3, 6]
8 年前
回复了 erhesto 创建的主题 » 用附加空格拆分python字符串(句子)

我大部分时间都避免使用regex,但这里的方法非常简单:

import re

given_string = 'This is my string!'
res = re.findall(r'\w+\W?', given_string)

# res ['This ', 'is ', 'my ', 'string!']