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. HTTPS学习(一):准备知识

    div.example { background-color: rgba(229, 236, 243, 1); color: rgba(0, 0, 0, 1); padding: 0.5em; mar ...

  2. 你可能不知道的 transition 技巧与细节

    CSS 中,transition 属性用于指定为一个或多个 CSS 属性添加过渡效果. 最为常见的用法,也就是给元素添加一个 transition,让其某个属性从状态 A 变化到状态 B 时,不再是非 ...

  3. Spark获取DataFrame中列的方式--col,$,column,apply

    Spark获取DataFrame中列的方式--col,$,column,apply 1.官方说明 2.使用时涉及到的的包 3.Demo 原文作者:大葱拌豆腐 原文地址:Spark获取DataFrame ...

  4. java HashMap and HashMultimap 区别

    http://stackoverflow.com/questions/19222029/what-is-difference-between-hashmap-and-hashmultimap The ...

  5. SpringBoot - 实现文件上传2(多文件上传、常用上传参数配置)

    在前文中我介绍了 Spring Boot 项目如何实现单文件上传,而多文件上传逻辑和单文件上传基本一致,下面通过样例进行演示. 多文件上传 1,代码编写 1)首先在 static 目录中创建一个 up ...

  6. kafka的演进历史

    首先如果我开始做一个消息队列,最开始的时候可能就是一台单机上的一个单一的log日志,不断地向这个日志中追加消息即可. 后来,可能由于一个log日志支撑不了太多的读写请求,于是就对这个log日志进行了拆 ...

  7. CPU中的程序是怎么运行起来的(预告篇)

    总述     最近一位朋友问我,我开发的代码是怎么运行起来的,我就开始给他介绍代码的预编译.汇编.编译.链接然后到一般的文件属性,再到代码运行.但是大佬问了我一句,CPU到底是怎么执行到每一个逻辑的, ...

  8. Codeforces Round #634 (Div. 3)

    D题想复杂了,花了好多时间,感觉也没时间看F了,就来写个题解蹭蹭访问量把^_^ 传送门:1335 A. Candies and Two Sisters 题意:你要把n个糖果分给两个人,两个人的糖果数不 ...

  9. poj 2398Toy Storage

    Toy Storage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3146   Accepted: 1798 Descr ...

  10. Codeforces Round #649 (Div. 2) C、Ehab and Prefix MEXs D、Ehab's Last Corollary 找环和点染色

    题目链接:C.Ehab and Prefix MEXs 题意; 有长度为n的数组a(下标从1开始),要求构造一个相同长度的数组b,使得b1,b2,....bi集合中没有出现过的最小的数是ai. mex ...