how to iterate through a nested list element by element to create a different string each time
Question:
I’m doing some practice problems and I’m trying to figure out how to go through nested lists so that it does this:
example list: [['a','b','c'],['d','e','f'],['g','h','j']]
expected: ['a','ab','abc','b','bc','c']
and it does this for each list
what I’ve tried doing so far:
idk = ""
for i in range(len(example_list)):
idk.join(example_list[i][i:i+1])
im confused on to go one by one when ive tried other ways i just get a huge string
Answers:
words=[]
for i in list:
for j in range(len(i)):
k=j;
temp=""
while k<len(i):
temp+=i[k]
words.append(temp)
I think this is what you are looking for
I’m doing some practice problems and I’m trying to figure out how to go through nested lists so that it does this:
example list: [['a','b','c'],['d','e','f'],['g','h','j']]
expected: ['a','ab','abc','b','bc','c']
and it does this for each list
what I’ve tried doing so far:
idk = ""
for i in range(len(example_list)):
idk.join(example_list[i][i:i+1])
im confused on to go one by one when ive tried other ways i just get a huge string
words=[]
for i in list:
for j in range(len(i)):
k=j;
temp=""
while k<len(i):
temp+=i[k]
words.append(temp)
I think this is what you are looking for