Python Coding Interview

Python Advanced

Use enumerate() to iterate over both indices and values

Debug problematic code with breakpoint()

Format strings effectively with f-strings

Sort lists with custom arguments

Use generators instead of list comprehensions to conserve memory

Define default values when looking up dictionary keys

Count hashable objects with the collections.Counter class

Use the standard library to get lists of permutations and combinations

enumerate()

enumerate() is a built-in function to iterate through a sequence and keep track of both the index and the number.

>>> list(range(11))
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >>> list(enumerate([1, 2, 3]))
[(0, 1), (1, 2), (2, 3)] >>> list(enumerate([1, 2, 3], start=10))
[(10, 1), (11, 2), (12, 3)]
 list = [45, 22, 14, 65, 97, 72].

for i, num in enumerate(numbers):
if num % 3 == 0:
numbers[i] = "fizz"
if num % 5 == 0:
numbers[i] = "buzz"
if num % 5 == 0 and num % 3 == 0:
numbers[i] = "fizzbuzz"

for i, num in enumerate(numbers):
if num % 5 == 0 and num % 3 == 0:
numbers[i] = "fizzbuzz"
elif num % 3 == 0:
numbers[i] = "fizz"
elif num % 5 == 0:
numbers[i] = "buzz"

Jupyter

Jupyter Notebook Interface

https://ipython.org/index.html

Jupyter Notebook

https://jupyter.readthedocs.io/en/latest/install.html

refs

https://realpython.com/lessons/python-coding-interview-tips-overview/

https://realpython.com/courses/python-range-function/

https://realpython.com/lessons/use-enumerate-keep-running-index/



xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


Python Coding Interview的更多相关文章

  1. Cracking the coding interview目录及资料收集

    前言 <Cracking the coding interview>是一本被许多人极力推荐的程序员面试书籍, 详情可见:http://www.careercup.com/book. 第六版 ...

  2. Cracking the coding interview

    写在开头 最近忙于论文的开题等工作,还有阿里的实习笔试,被虐的还行,说还行是因为自己的水平或者说是自己准备的还没有达到他们所需要人才的水平,所以就想找一本面试的书<Cracking the co ...

  3. 转:Top 10 Algorithms for Coding Interview

    The following are top 10 algorithms related concepts in coding interview. I will try to illustrate t ...

  4. Cracking the coding interview 第一章问题及解答

    Cracking the coding interview 第一章问题及解答 不管是不是要挪地方,面试题具有很好的联系代码总用,参加新工作的半年里,做的大多是探索性的工作,反而代码写得少了,不高兴,最 ...

  5. Cracking the Coding Interview(Trees and Graphs)

    Cracking the Coding Interview(Trees and Graphs) 树和图的训练平时相对很少,还是要加强训练一些树和图的基础算法.自己对树节点的设计应该不是很合理,多多少少 ...

  6. Cracking the Coding Interview(Stacks and Queues)

    Cracking the Coding Interview(Stacks and Queues) 1.Describe how you could use a single array to impl ...

  7. crack the coding interview

    crack the coding interview answer c++ 1.1 #ifndef __Question_1_1_h__  #define __Question_1_1_h__  #i ...

  8. 《Cracking the Coding Interview》读书笔记

    <Cracking the Coding Interview>是适合硅谷技术面试的一本面试指南,因为题目分类清晰,风格比较靠谱,所以广受推崇. 以下是我的读书笔记,基本都是每章的课后习题解 ...

  9. python coding style guide 的高速落地实践

    python coding style guide 的高速落地实践 机器和人各有所长,如coding style检查这样的可自己主动化的工作理应交给机器去完毕,故发此文帮助你在几分钟内实现coding ...

随机推荐

  1. 宝塔Linux命令

    安装宝塔 Centos安装脚本 5.7:yum install -y wget && wget -O install.sh http://download.bt.cn/install/ ...

  2. 第一个 IDEA 应用程序

    新建 Java Web 项目 打开 IDEA -> Create New Project 选择 Java -> Java EE -> Web Application 选择工作空间 项 ...

  3. Defining Go Modules

    research!rsc: Go & Versioning https://research.swtch.com/vgo shawn@a:~/gokit/tmp$ go get --helpu ...

  4. 活动精彩实录 | 王峰:Cassandra在360的多场景应用及未来趋势

    点击此处观看完整活动视频 大家好,我是360的王峰,我今天主要通过Cassandra在多场景下的应用来介绍一下Cassandra在360落地的情况. 我会从以下这几个方面进行介绍.首先介绍下Cassa ...

  5. Python爬虫学习笔记(三)

    Cookies: 以抓取https://www.yaozh.com/为例 Test1(不使用cookies): 代码: import urllib.request # 1.添加URL url = &q ...

  6. libuv线程通信

    目录 1.说明 2.API 2.1.uv_async_init 2.2.uv_async_send 2.3.uv_close 3.代码示例 1.说明 用于多线程之间传递参数 2.API 2.1.uv_ ...

  7. 洛谷P2573

    Description \(n\) 个点,有各自的高度. \(m\) 条道路,有各自的长度,每条可连接两个点. 规定只能从高点走向低点,可以回到原来的某个位置走不同的道路. 求在行走道路尽量短的情况下 ...

  8. python--基础3(流程语句)

    资源池 链接:https://pan.baidu.com/s/1OGq0GaVcAuYEk4F71v0RWw 提取码:h2sd 本章内容: if判断语句 for循环语句 while循环语句 break ...

  9. 原生js拖拽功能制作滑动条实例教程

    拖拽属于前端常见的功能,很多效果都会用到js的拖拽功能.滑动条的核心功能也就是使用js拖拽滑块来修改位置.一个完整的滑动条包括 滑动条.滑动痕迹.滑块.文本 等元素,先把html代码写出来,如下所示: ...

  10. 使用VisualStudio直接运行简单的C#语句

    场景 经常有这样的需求, 想要测试一些简单的C#语法, 或者测试一下 文件 目录 操作相关的Api, 通常的做法是建立一个C#控制台项目, 然后写代码测试, 但是这样的做法对测试简单的语法和Api来说 ...