算法练习之字符串切割及统计每个字符出现的次数

 

 

#!/usr/bin/env python
# -*-coding:utf-8-*-
# @Author   : clover
# @Time    : 2020/9/15 10:13

def testsplit():
    str1 = "www.baidu.com www.baidu.com"
    list1 = str1.split('.')
    print(list1)  # ['www', 'baidu', 'com www', 'baidu', 'com']
    print("-----------分割线--------------")
    a = list1
    dict = {}
    for key in a:
        dict[key] = dict.get(key, 0) + 1
    print(dict)
    print("-----------分割线--------------")
    L = list(dict.items())
    print(L)

testsplit()

 

posted @ 2020-09-17 09:56  eosclover  Views(236)  Comments(0Edit  收藏  举报