Problem:
How do I loop through a list, look at the first char in each list item. If the first char = "0" then remove the “0” then look at next item in list for same evaluation. else: leave it as is.
Code thus far:
gList = ["094G.016", "094G.019", "094G.005", "194G.015"]
for x in gList:
lGrid[i].lstrip("0")
print gList
else:
pass
Desired Output:
gList = ["94G.016", "94G.019", "94G.005", "194G.015"]
Research:
I can use gList.lstrip("0") to remove the zero from the first item in the list but don’t know how to get it to move to the next entry and repeat the process.
Alternatively:
I know I can use gList[0][0] to select the first list/char item but again need way for it to loop through the list.
EDIT: Using a generator:
Code thus far:
def rem0(data):
(x.lstrip('0') for x in lGrid)
yield x
for i in rem0(lGrid):
print i
Desired Output:
gList = ["94G.016", "94G.019", "94G.005", "194G.015"]
improving your approach:
with every iteration x points to the current item, so apply
lstrip()on x not ongListusing item:
using index: