+ 1
Lists inside list and show the first two items of the inner list and this via for loop ?
Lists inside list and show the first two items of the inner list and this via for loop ?
5 Antworten
+ 2
does this help ?
for innerlist in outerlist:
print(innerlist[0] + "" + innerlist[1])
this two lines are hardcoded so if you want to use them you need to make sure you have more than two items in the inner list if you don't want any errors and if you want to show every item in the inner list you shall use this:
for innerlist in outerlist:
for item in innerlist:
print(item)
print("\n")
+ 1
Try the first code i mentioned
+ 1
I will try thank you
+ 1
Working on Bouderbala Amine's code; you just need a check that verifies whether <innerlist> contains more than one item.
for innerlist in outerlist:
if len(innerlist) > 1:
print(innerlist[0], innerlist[1])
The check for <innerlist> item count prevents printing <innerlist> that has less than 2 items.
0
First thanks for yoir note but the problem how to show the first two items of inner list