aladdin hasp

    科技2026-09-30  16

    aladdin hasp

    Ramprabhu Sreekrishnan Ramprabhu Sreekrishnan Follow 跟随 Aug 30 8月30

    Iterable and Iterator in Python using Aladdin story.

    使用Aladdin故事的Python中的Iterable和Iterator。

    Generally we use for-loops to iterate or traverse across the elements within a List or Tuples.

    通常,我们使用for循环在List或Tuple中的元素上进行迭代或遍历。

    For loop for List 清单的循环

    In the for-loop after processing the first element in the list control moves to the next element , this process of traveling from one element to other is called Iteration. For loop works in the same way for Tuples, Dictionaries, Strings and Sets.

    在处理完列表控件中的第一个元素后,在for循环中移动到下一个元素,这种从一个元素移动到另一个元素的过程称为迭代。 For循环对于元组,字典,字符串和集合的工作方式相同。

    There are two ways to do the same iteration process without using For-Loop. The first method is Indexing

    有两种方法可以执行相同的迭代过程而无需使用循环。 第一种方法是索引

    Index method for List 列表的索引方法

    But this indexing method can be used only for List,Tuples and strings.They Cannot be used with Sets and Dictionaries because they are unordered.

    但是此索引方法只能用于List,Tuples和字符串。由于它们是无序的,因此不能与Sets和Dictionary一起使用。

    Error while trying for Index with Sets 尝试使用集合索引时出错

    Iterator Protocol:

    迭代器协议:

    The second method we can use is Iterator protocol. Iterator protocol is nothing but working with Iterator and Iterable. Most of us are confused with these two terms Iterable and Iterator.

    我们可以使用的第二种方法是Iterator协议。 迭代器协议不过是与Iterator和Iterable一起使用。 我们大多数人对这两个术语Iterable和Iterator感到困惑。

    Let’s have a close look at them now.

    现在让我们仔细看看它们。

    list2 the “iterable” 列出“可迭代”

    Everything that we can loop over is called a Iterable. In the above fig of for Loop list is an iterable.

    我们可以循环的所有内容都称为Iterable。 在上面的for循环图中,列表是一个可迭代的。

    Now these Iterables do give us the Iterators. They do give these iterators using a function Iter().Iterable usually call this Inbuilt function iter() and generate the Iterator. Using this Iterator we can traverse across the individual elements in the Iterable.

    现在这些可迭代对象确实为我们提供了迭代器。 他们确实使用函数Iter()给这些迭代器。Iterable通常调用此内置函数iter()并生成Iterator。 使用此迭代器,我们可以遍历Iterable中的各个元素。

    Let’s use our friend Aladdin to explain this Iterable concept.

    让我们用我们的朋友阿拉丁来解释这个Iterable概念。

    Consider Aladdin as the Literable and the Genie as the iterator which does things for Aladin.Aladdin brings the Genie out using the Magic lamp, so now the magic lamp is our ITER() object.

    假设Aladdin是Literable,而Genie是为Aladin做事的迭代器.Aladdin使用Magic灯将Genie带出,所以现在魔术灯是我们的ITER()对象。

    Aladdin → Iterable

    阿拉丁→可迭代

    Magic Lamp → Iter()

    魔术灯→Iter()

    Genie → Iterator.

    精灵→迭代器。

    In the above example the list is the iterable and it uses the iter(list) function to create an iterator for list. Now we can use the Next(iterator) to extract individual element of the iterable.

    在上面的示例中,列表是可迭代的,并且它使用iter(list)函数创建列表的迭代器。 现在我们可以使用Next(iterator)提取可迭代的单个元素。

    翻译自: https://medium.com/@prabhucs01/iterable-and-iterator-in-python-using-aladdin-story-ff936994662

    aladdin hasp

    相关资源:ALADDIN加密狗hasp驱动安装
    Processed: 0.009, SQL: 9