1.写函数: 根据范围获取其中3和7整除的所有数的和,并返回调用者: 符合条件的数字个数以及符合条件的数字的总和,如:def func(start,end): def func(start,end): count=0 s=0 for i in range(start,end): if i%3==0 and i%7==0: count+=1 s+=i print(i) return s,count print(func(0,100)) 2.函数传递参数时,是引用还是复制值,并证明引用 def te
#!/usr/bin/env python #def f1(x) : # return x > 22 ret = filter(lambda x : x > 22 ,[11,22,33,44]) print(ret) for i in ret : print(i) # 普通条件语句 if 1 == 1: name = 'wupeiqi' else: name = 'alex' # 三元运算 name = 'wupeiqi' if 1 == 1 else 'alex'
#!/usr/bin/env python #有如下值集合[11,22,33,44,55,66,77,88,99,90...],将所有大于66值保存至字典的一个key中,将小于66的值保存至大二个key的值 li = [11,22,33,44,55,66,77,88,99,90] person = {">66":[],"<=66":[]} for i,j in enumerate(li,0) : if int(j) > 66 : person[&q
方法一: li = [11,22,33,44,55,66,77,88,99]s = []m = []for i in li: if i <= 55: s.append(i) else: m.append(i)print(s)print(m)方法二: li = [11,22,33,44,55,66,77,88,99]dic = { 'k1':[], 'k2':[]}for i in li: if i <= 55: dic['k1'].append(i) else: dic['k2'].appen
在.net环境下,精确的测量出某段代码运行的时长,在网络通信.串口通信以及异步操作中很有意义.现在做了简单的总结.具体代码如下: (1).首先 using System.Diagnostics; (2).主要代码 Stopwatch sw = new Stopwatch(); //监听循环10000次需要的时长 // 计时开始 sw.Start(); for (int i = 0; i < 10000;i++ ) { // to do } // 计时结束 sw.Stop(); Console.W
2017/11/22 Leetcode 日记 136. Single Number Given an array of integers, every element appears twice except for one. Find that single one. class Solution { public: int singleNumber(vector<int>& nums) { int len = nums.size(); ]; ; i < len; i++){