以下程序如何封装到一个类中
importrandomimportjsondefrandomlist():listname=[]foriinrange(10):listname.append(rand...
import randomimport json
def randomlist(): listname = [] for i in range(10): listname.append(random.randint(1,80)) return listname
list1=randomlist();list2=randomlist();list3=randomlist()print list1,list2,list3
totallist = list1[:]totallist.extend(list2)totallist.extend(list3)
print totallistjishu,oushu = [],[]for i in totallist: if i%2 == 1 and i not in jishu: jishu.append(i) elif i%2 == 0 and i not in oushu: oushu.append(i)
jishu.sort()oushu.sort()
p={}p['a'] = list1
p['b'] = list2
p['c'] = list3
p['d'] = totallist
p['e']=jishu
p['f']=oushu
f=file('p.txt','w')f.write(json.dumps(p))f.close()
f=file('p.txt')while True: line =f.readline() if len(line)==0: break print line, f.close
print p 展开
def randomlist(): listname = [] for i in range(10): listname.append(random.randint(1,80)) return listname
list1=randomlist();list2=randomlist();list3=randomlist()print list1,list2,list3
totallist = list1[:]totallist.extend(list2)totallist.extend(list3)
print totallistjishu,oushu = [],[]for i in totallist: if i%2 == 1 and i not in jishu: jishu.append(i) elif i%2 == 0 and i not in oushu: oushu.append(i)
jishu.sort()oushu.sort()
p={}p['a'] = list1
p['b'] = list2
p['c'] = list3
p['d'] = totallist
p['e']=jishu
p['f']=oushu
f=file('p.txt','w')f.write(json.dumps(p))f.close()
f=file('p.txt')while True: line =f.readline() if len(line)==0: break print line, f.close
print p 展开
2013-10-30
展开全部
java的?创建一个class文件,头部加个你的import,添加一个方法,然后把代码拷贝进去,
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询