社区所有版块导航
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
反馈   公告   社区推广  
产品
短视频  
印度
印度  
私信  •  关注

Jordan Brière

Jordan Brière 最近创建的主题
Jordan Brière 最近回复了
5 年前
回复了 Jordan Brière 创建的主题 » 用for in语句替换列表中的项(Python)

我想你想要这样的东西:

int_list = [2, 33, 4, 55, 5, 56, 34, 6, 6, 76, 78657, 234, 3, 4]
New = []

for N in int_list:
    New.append(str(N) + ('small' if N < 30 else 'large'))
print(New)

结果:

['2small', '33large', '4small', '55large', '5small', '56large', '34large', '6small', '6small', '76large', '78657large', '234large', '3small', '4small']
5 年前
回复了 Jordan Brière 创建的主题 » 在python中替换字典的值

你可以用 eval

d2 = {key: eval(str(value)) for key, value in d1.items()}

{
    ('a', 'b'): 300.0,
    ('b', 'c'): 0.21000000000000002,
    ('a', 'c'): 0.462,
    ('c', 'e'): 0.68,
    ('b', 'a'): 0.21000000000000002,
    ('c', 'd'): 4.2
}