range(len(columns3))
with enumerate(columns3)
117 )
118 cell.cell.input_value = columns2[colnum]
119 spr_client.update(cell)
120 for colnum in range(len(columns3)):121 cell = spr_client.get_cell(
122 spreadkey, sheet.get_worksheet_id(), 3, colnum + 1
123 )
range(len(columns2))
with enumerate(columns2)
111 )
112 cell.cell.input_value = columns[colnum]
113 spr_client.update(cell)
114 for colnum in range(len(columns2)):115 cell = spr_client.get_cell(
116 spreadkey, sheet.get_worksheet_id(), 2, colnum + 1
117 )
range(len(columns))
with enumerate(columns)
105 for yr in ["2011", "2013", "2015"]:
106 print("Adding worksheet for year: %s" % (yr,))
107 sheet = spr_client.add_worksheet(spreadkey, yr, 10, len(columns))
108 for colnum in range(len(columns)):109 cell = spr_client.get_cell(
110 spreadkey, sheet.get_worksheet_id(), 1, colnum + 1
111 )
range(len(columns))
with enumerate(columns)
85 for yr in ["2011", "2012", "2013", "2014", "2015"]:
86 print("Adding worksheet for year: %s" % (yr,))
87 sheet = spr_client.add_worksheet(spreadkey, yr, 10, len(columns))
88 for colnum in range(len(columns)):89 cell = spr_client.get_cell(
90 spreadkey, sheet.get_worksheet_id(), 1, colnum + 1
91 )
range(len(columns))
with enumerate(columns)
60 rows = []
61 # Units row
62 entry = gdata.spreadsheets.data.ListEntry()
63 for i in range(len(columns)):64 entry.set_value(columns[i].replace(" ", ""), units[i])
65 rows.append(entry)
66 for plot in plots:
Using range(len(...))
is not pythonic. Python does not have not index-based loops. Instead, it uses collection iterators.
Python has a built-in method enumerate
which adds a counter to an iterable.
Using this, you can access the counter and the value from the iterable at the same time.
It is therefore recommended to replace range(len(...))
with enumerate(...)
.
for index in range(len(mylist)):
...
for index, element in enumerate(mylist):
...