美文网首页
python VS es6

python VS es6

作者: timehorse | 来源:发表于2019-08-03 23:20 被阅读0次

今天用python写一个leetcode上的算法,由于好久没写python了,连pyhon的列表和字典遍历都忘了,问了古哥后才想起来:

array = [2, 5, 7, 11, 13]
target = 13

def sum_func(array, target):
  map_of_array = {}
  for index, value in enumerate(array):
    map_of_array[value] = index
  
  for key, value in map_of_array.items():
    if target - key in map_of_array.keys():
      print(value, map_of_array[target-key])

sum_func(array, target)

这段代码感觉似曾相识,想了一下发现,如果改写成es6,你发现语法很类似。也就是js的发展趋势是在向python靠拢。你看,上面的列表和字典,以及for循环跟python是多么相似啊

有一种说法是“能用js实现的,最后一定都会用js实现”,那么这里可以说:“能跟python长的像的,最后一定会像python”
因为:python的语法真的是最人性化的了,跟人类的理解更趋近。

相关文章

网友评论

      本文标题:python VS es6

      本文链接:https://www.haomeiwen.com/subject/hqasdctx.html