本篇将开始介绍python高阶函数map/reduce/filter的用法,更多内容请参考:Python学习指南 map/reduce Python内建了map()和reduce()函数. 如果你读过Google的那篇大名鼎鼎的论文"MapReduce: Simplified Data Processing on Large Clusters",你就能大概明白map/reduce的概念. 我们先看map.map()函数接收两个参数,一个是函数,一个是序列,map将传入的函数依次作用到序…
python. pandas(series,dataframe,index,reindex,csv file read and write) method test import pandas as pdimport numpy as np def testpandas(): p = pd.Series([1,2,3,4,5],index =('a','b','c','d','e')) print(p) cities = {'bejing':5500,'shanghai':5999,'shezh…
lambda函数也叫匿名函数,即,函数没有具体的名称.先来看一个最简单例子: def f(x): return x**2 print f(4) Python中使用lambda的话,写成这样 g = lambda x : x**2 print g(4) lambda表达式在很多编程语言都有对应的实现.比如C#: var g = x => x**2 Console.WriteLine(g(4)) 那么,lambda表达式有什么用处呢?很多人提出了质疑,lambda和普通的函数相比,就是省去了函数名称…
面试题之中的一个. 下面代码能执行吗? l = [1,2,3,4,5] for i in range(0,len(l)): print i if l[i] % 2 == 0: del l[i] print l 结果: Traceback (most recent call last): File "D:\1.py", line 3, in <module> if l[i] % 2 == 0: IndexError: list index out of range 啊.由于随…
# -*- coding: utf8 -*-'''https://oj.leetcode.com/problems/median-of-two-sorted-arrays/ There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays.The overall run time complexity should be O(log (m+n)).…
Suppose Andy and Doris want to choose a restaurant for dinner, and they both have a list of favorite restaurants represented by strings. You need to help them find out their common interest with the least list index sum. If there is a choice tie betw…