欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

跟书友汇德天学python,字典新构,字符串新解!抢位吧!

程序员文章站 2022-05-02 12:55:38
...

今天内容简单,希望通过抛砖引玉,大家一起交流!

上干货!利用字符拆分,字符位数和字符对应重组,组成字典。以下是代码实现过程!

stri = "my name is abc"
str_num = []
  
   
stri2 = stri.split(" ")

for i in stri2:

    stri2
    str_num.append(len(i))

s_dict = dict(zip(stri2,str_num))

print(s_dict)