Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 5938

Python scripting help

$
0
0

@djnelson75 wrote:

This is more a python question than a Rhino question, as I am still learning python. So I have a list and I wanted to find the indexes for each item if they occur more than once. The answer I found on Stackover flow was the following:

Fruit = ['apple','pear','peach','pear']
index = [i for i, x in enumerate(Fruit) if x == "pear"]
print(index)

result = [1, 3]

Since this seem extremely condensed, I was wondering if anyone would be willing describe what is happening in lamen terms. I understand what the enumerate() function does where is returns the index and the value of given list, just not sure what the i for i is doing.

Thanks for the help in advance.

Posts: 5

Participants: 3

Read full topic


Viewing all articles
Browse latest Browse all 5938

Trending Articles