|
也是自己之前学习的笔记。
读文件
file_obj2=open('hello.txt','w')
conta='my name is Bb'
file_obj2.write(conta)
v=file_obj2.readlines()
print v
输出不唯一数1 (这是一个国外Python练习网站上的题目 我其他博文有介绍 )
def checkio(data):
from collections import Counter
nonunique = Counter(data) - Counter(set(data))
return [x for x in data if x in nonunique]
print checkio([1,31,5,13,13,1,1])
print counter(set([1,31,5,13,13,1,1]))
输出不唯一数2
#Your optional code here
#You can import some modules or create additional functions
def checkio(data):
return [x for x in data if data.count(x) > 1]
#Some hints
#You can use list.count(element) method for counting.
#Create new list with non-unique elements
#or remove elements from original list (but it's bad practice for many real cases)
#Loop over original list
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == "__main__":
assert isinstance(checkio([1]), list), "The result must be a list"
assert checkio([1, 2, 3, 1, 3]) == [1, 3, 1, 3], "1st example"
assert checkio([1, 2, 3, 4, 5]) == [], "2nd example"
assert checkio([5, 5, 5, 5, 5]) == [5, 5, 5, 5, 5], "3rd example"
assert checkio([10, 9, 10, 10, 9, 8]) == [10, 9, 10, 10, 9], "4th example"
#python while 循环语句
i=1;
s=0;
while i=80:
print 'a'
elif count>=70:
print'b'
else :
print 'nono'
#字符区域代码#
sex=raw_input('put your sex')
if sex=='Male':
print 'right'
else:
print 'no'
#python if分支语句表达式构造 非0 即为真#
#关系表达式 > < = 逻辑表达式 and or not
#网络刷博客浏览量#
import os
import webbrowser as web
import time
i=0
while i |
|