
python笔记
coursesa python 3 programming 笔记
sheeplil
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
coursesa课程 Python 3 programming course_2_assessment_8 sorted练习题
Given the same dictionary, medals, now sort by the medal count. Save the three countries with the highest medal count to the list, top_three. medals = {'Japan':41, 'Russia':56, 'South Korea':21, 'Un...原创 2020-04-12 20:39:20 · 1967 阅读 · 0 评论 -
coursesa课程 Python 3 programming 排序函数sorted的可选参数
sorted(iterable[, key][, reverse]) 从 iterable 中的项目返回新的排序列表。 有两个可选参数,必须指定为关键字参数。 key 指定一个参数的函数,用于从每个列表元素中提取比较键:key=str.lower。默认值为 None (直接比较元素)。 reverse 是一个布尔值。如果设置为 True,那么列表元素将按照每个比较反转进行排序。 You w...原创 2020-04-11 21:00:28 · 834 阅读 · 0 评论 -
coursesa课程 Python 3 programming course_2_assessment_7 多参数函数练习题
Write a function called checkingIfIn that takes three parameters. The first is a required parameter, which should be a string. The second is an optional parameter called direction with a default valu...原创 2020-04-10 22:49:53 · 1053 阅读 · 0 评论 -
coursesa课程 Python 3 programming Anonymous functions with lambda expressions lambda表达式
def f(x): return x - 1 print(f) print(type(f)) print(f(3)) print(lambda x: x-2) print(type(lambda x: x-2)) print((lambda x: x-2)(6))原创 2020-04-10 20:22:34 · 177 阅读 · 0 评论 -
course_2_assessment_6
1.Write a function, sublist, that takes in a list of numbers as the parameter. In the function, use a while loop to return a sublist of the input list. The sublist should contain the same values of t...原创 2020-04-09 23:52:40 · 1044 阅读 · 0 评论 -
coursesa课程 Python 3 programming The while Statement
1、Write a while loop that is initialized at 0 and stops at 15. If the counter is an even number, append the counter to a list called eve_nums n = 0 eve_nums = list() while n <= 15: if n % 2 =...原创 2020-04-09 14:25:11 · 519 阅读 · 0 评论 -
coursesa课程 Python 3 programming Accumulating Multiple Results In a Dictionary 统计文件的字母数量
f = open('scarlet.txt', 'r') txt = f.read() # now txt is one long string containing all the characters x = {} # start with an empty dictionary for c in txt: if c not in x: # we have not se...原创 2020-04-06 21:13:02 · 222 阅读 · 0 评论 -
coursesa课程 Python 3 programming Dictionary methods 字典的方法
Note Technically, .keys(), .values(), and .items() don’t return actual lists. Like the range function described previously, in python 3 they return objects that produce the items one at a time, rathe...原创 2020-04-06 19:17:05 · 267 阅读 · 0 评论 -
coursesa课程 Python 3 programming 文件中如果单词包含‘p’,就输出那个单词
Challenge: Using the file school_prompt.txt, if the character ‘p’ is in a word, then add the word to a list called p_words. school_prompt = open('school_prompt.txt','r') chars = school_prompt.read() w...原创 2020-04-05 17:34:20 · 341 阅读 · 0 评论 -
coursesa课程 Python 3 programming 输出每一行句子的第三个单词
题目:Using the file school_prompt.txt, assign the third word of every line to a list called three school_prompt = open('school_prompt.txt','r') chars = school_prompt.readlines() three = list() for word ...原创 2020-04-05 17:24:16 · 540 阅读 · 0 评论 -
coursesa课程 Python 3 programming 统计文件有多少单词
题目:We have provided a file called emotion_words.txt that contains lines of words that describe emotions. Find the total number of words in the file and assign this value to the variable num_words. emo...原创 2020-04-05 17:11:38 · 427 阅读 · 0 评论 -
coursesa python 3 Writing data to a CSV File,将数据写入CSV格式的文件
First, using .format() makes it really clear what we’re doing when we create the variable row_string. We are making a comma separated set of values; the {} curly braces indicated where to substitute i...原创 2020-04-05 16:28:21 · 175 阅读 · 0 评论 -
coursesa Python 3 Reading and Processing a File ,文件的处理和读写
#1. Open the file using with and open. #2. Use .readlines() to get a list of the lines of text in the file. #3. Use a for loop to iterate through the strings in the list, each being one line from the ...原创 2020-04-05 12:43:59 · 206 阅读 · 0 评论