Monday, December 18, 2006

Enumerate function @ Python

class enumerate(object)

| enumerate(iterable) -> iterator for index, value of iterable

|

| Return an enumerate object. iterable must be an other object that supports

| iteration. The enumerate object yields pairs containing a count (from

| zero) and a value yielded by the iterable argument. enumerate is useful

| for obtaining an indexed list: (0, seq[0]), (1, seq[1]), (2, seq[2]), ...

|

| Methods defined here:

|

| __getattribute__(...)

| x.__getattribute__('name') <==> x.name

|

| __iter__(...)

| x.__iter__() <==> iter(x)

|

| next(...)

| x.next() -> the next value, or raise StopIteration

|

| ----------------------------------------------------------------------

| Data and other attributes defined here:

|

| __new__ =

| T.__new__(S, ...) -> a new object with type S, a subtype of T

ex::

1)
for index,word in enumerate(range(10)):
... print index,word
...
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9

2)
for index,word in enumerate(range(10)):
... print "%s %f" % (index,word)
...
0 0.000000
1 1.000000
2 2.000000
3 3.000000
4 4.000000
5 5.000000
6 6.000000
7 7.000000
8 8.000000
9 9.000000

 

No comments: