python练习实例014的简单介绍

python练习实例014的简单介绍import string

本文目录一览:

求解 python 练习题

import string

def makeWordList(input_file, output_file):

    

    table = string.maketrans(“”, “”)

    try:

        word_list = dict()

        for line in open(input_file, ‘r’):

            line = line.translate(table, string.punctuation).rstrip(‘\r\n’).split(‘ ‘)

            for word in line:

                if not word in word_list:

                    word_list[word] = 1

                else:

                    word_list[word] += 1

        f = open(output_file, ‘w’)

        for k,v in word_list.items():

            line = ‘%s %s\r\n’ % (k,v)

            f.write(line)

    except:

        print input_file,’not exist’

            

            

    

makeWordList(‘input.txt’, ‘output.txt’)

推荐几个适合新手练手的Python项目

《Python实战:四周实现爬虫系统》百度网盘免费下载

链接:

提取码: xbdu   

Python实战:四周实现爬虫系统

python练习实例014的简单介绍

Day014 Python 数据类型之元组

今儿我们再续前缘,接着List开始说。

元组和List特别像,区别是元组中的数据不可以修改。

为表区别,元组的标识符用的是小括号(),而List是用的中括号[]

举个栗子

tup2 = (1, 2, 3, 4, 5 )

不可修改属性,这也是和List最大区别

元组中的元素值也不能修改,但可以用del语句,删除整个元组

以上

我正在从0开始学习Python,想找伙伴一起学习讨论,感兴趣的伙伴可以一起~

Python实现的排列组合计算操作示例

Python实现的排列组合计算操作示例

本文实例讲述了Python实现的排列组合计算操作。分享给大家供大家参考,具体如下:

1. 调用 scipy 计算排列组合的具体数值

from scipy.special import comb, perm

perm(3, 2)

6.0

comb(3, 2)

3.0

2. 调用 itertools 获取排列组合的全部情况数

from itertools import combinations, permutations

permutations([1, 2, 3], 2)

itertools.permutations at 0x7febfd880fc0

# 可迭代对象

list(permutations([1, 2, 3], 2))

[(1, 2), (1, 3), (2, 1), (2, 3), (3, 1), (3, 2)]

list(combinations([1, 2, 3], 2))

[(1, 2), (1, 3), (2, 3)]

python入门教程

《【3】学习视频》百度网盘资源免费下载

链接:

提取码:m6tm

【3】学习视频|python视频教程|Python入门基础视频教程|lets python 视频教程|Lets-python-017-文件和输入输出01.avi|Lets-python-016-条件和循环02-练习题和生成器.avi|Lets-python-015-条件和循环01.avi|Lets-python-014-映射和集合02.avi|Lets-python-013-映射和集合01.avi|Lets-python-012-序列04-02.avi|Lets-python-012-序列04-01.avi|Lets-python-011-del和getattr.avi|Lets-python-010-序列03.avi|lets-python-009-序列02.avi|Lets-python-008-序列01.avi  

Python视频教程,百度云

[python视频教程] lets python视频教程免费下载

链接:

提取码:dxpn

[python视频教程] lets python 视频教程|Lets-python-017-文件和输入输出01.avi|Lets-python-016-条件和循环02-练习题和生成器.avi|Lets-python-015-条件和循环01.avi|Lets-python-014-映射和集合02.avi|Lets-python-013-映射和集合01.avi|Lets-python-012-序列04-02.

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
转载请注明出处: https://daima100.com/23370.html

(0)
上一篇 2023-10-31
下一篇 2023-10-31

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注