Find:

In a sense, find is the opposite of the [] operator. Instead of taking an index and extracting the corresponding character, it takes a character and finds the index where that character appears. If the character is not found, the function returns -1.

This pattern of computation – traversing a sequence and returning when we find what we are looking for – is called a search.

Looping and counting

The following program counts the number of times the letter a appears in a string:

This program demonstrates another pattern of computation called a counter. The variable count is initialized to 0 and then incremented each time an a is found. When the loop exits, count contains the result – the total number of a’s.

from Thinking in Python

Find and counter的更多相关文章

  1. UNITY自带的PACKAGE的UTILITY 里面有一个自带的FPS COUNTER

    UNITY自带的PACKAGE的UTILITY 里面有一个自带的FPS COUNTER 可用,但是脚本是保密的?

  2. [LeetCode] Design Hit Counter 设计点击计数器

    Design a hit counter which counts the number of hits received in the past 5 minutes. Each function a ...

  3. collections 模块(namedtuple, deque, Counter )

    基本介绍 我们都知道,Python拥有一些内置的数据类型,比如str, int, list, tuple, dict等, collections模块在这些内置数据类型的基础上,提供了几个额外的数据类型 ...

  4. Performance Monitor2:Peformance Counter

    Performance Counter 是量化系统状态或活动的一个数值,Windows Performance Monitor在一定时间间隔内(默认的取样间隔是15s)获取Performance Co ...

  5. Python_Day_05 计数器(counter),有序字典(OrderDict),默认字典(defaultdict),可命名元祖(namedtuple),双向队列(deque),单项队列(deuqe.Queue)

    Counter(计数器) 是一个字典的子类,存储形式同样为字典,其中存储的键为字典的元素,值为元素出现的次数,在使用之前我们需要先导入文件 import collections 初始化一个计数器 im ...

  6. 利用CSS计数函数counter()实现计数

    要实现li列表计数比较简单,直接设置list-style-type即可,但是要实现非li列表计数该怎么办呢,counter()可以轻松实现 body{counter-reset:section 0 s ...

  7. 计数器(counter),有序字典(OrderDict),默认字典(defaultdict),可命名元祖(namedtuple),双向队列(deque),单项队列(deuqe.Queue)

    Python_Day_05 计数器(counter),有序字典(OrderDict),默认字典(defaultdict),可命名元祖(namedtuple),双向队列(deque),单项队列(deuq ...

  8. LeetCode Design Hit Counter

    原题链接在这里:https://leetcode.com/problems/design-hit-counter/. 题目: Design a hit counter which counts the ...

  9. CacheManager COUNTER

    CacheClient.AddOrUpdate("COUNTER", 0, v => Convert.ToInt32(v) + 1);

  10. codeforces 495A. Digital Counter 解题报告

    题目链接:http://codeforces.com/problemset/problem/495/A 这个题目意思好绕好绕~~好绕~~~~~,昨天早上做得 virtual 看不懂,晚上继续看还是,差 ...

随机推荐

  1. 鸟哥的Linux私房菜-----11、压缩指令与正则表示法

  2. ios中NSUserDefaults的使用方法

    ios中NSUserDefaults的使用方法 NSUserDefaults类提供了一个与默认系统进行交互的编程接口.NSUserDefaults对象是用来保存.恢复应用程序相关的偏好设置,配置数据等 ...

  3. 怎样更好的深入学习andorid

    把主要的控件  基本布局 基本组件  数据存储都熟悉一边,在看网络的时候,有点不知道怎么搞了.由于一直用c开发,但接触socket也不多,这两天把java的socket编程熟悉了下.找了非常多书,可是 ...

  4. 排序(3)---------冒泡排序(C语言实现)

    说到冒泡排序,大一的时候第一次学习这个排序算法,可能大家不知道,"冒泡"在我说的方言里面是吹牛逼的意思. 所以就认为这个排序算法特吹牛逼有木有. 相信大家对全部的排序算法,这个想必 ...

  5. JDBC-Statement 对象

    Statement 对象 一旦我们获得了数据库的连接,我们就可以和数据库进行交互.JDBC 的 Statement,CallableStatement 和 PreparedStatement 接口定义 ...

  6. 数据结构—单链表(类C语言描写叙述)

    单链表 1.链接存储方法 链接方式存储的线性表简称为链表(Linked List). 链表的详细存储表示为: ① 用一组随意的存储单元来存放线性表的结点(这组存储单元既能够是连续的.也能够是不连续的) ...

  7. 继承QWidget的派生类控件不能设置QSS问题解决(使用style()->drawPrimitive(QStyle::PE_Widget,也就是画一个最简单最原始的QWidget,不要牵扯其它这么多东西)

    自定义控件时基类用了QWidget,发现qss设置不起作用,需要重载其paintEvent函数即可: 如下代码: void CCustomWidget::paintEvent(QPaintEvent* ...

  8. 山东理工oj--1912--IP地址(水题)

     IP地址 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 2011年2月3日,国际互联网名称与数字地址分配机构(ICANN) ...

  9. CxImage 简单配置与使用

    CxImage 简单配置与使用 如果本篇文章还不能解决你在生成解决方案以及便宜过程中的问题 请参阅: http://blog.csdn.net/afterwards_/article/details/ ...

  10. ksh简介

    -- Start 什么是 Shell 如果把 Linux 比作一个蛋,那么 Shell 就是蛋壳,我们需要通过 Shell 来使用系统. Shell 的种类 最早的 Shell 是 Bourne Sh ...