+ 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 ?

21st Sep 2019, 11:46 AM
Mohamed Rashidey Hasan
Mohamed Rashidey Hasan - avatar
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")
21st Sep 2019, 12:05 PM
Bouderbala Amine
Bouderbala Amine - avatar
+ 1
Try the first code i mentioned
21st Sep 2019, 12:31 PM
Bouderbala Amine
Bouderbala Amine - avatar
+ 1
I will try thank you
21st Sep 2019, 12:38 PM
Mohamed Rashidey Hasan
Mohamed Rashidey Hasan - avatar
+ 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.
21st Sep 2019, 2:20 PM
Ipang
0
First thanks for yoir note but the problem how to show the first two items of inner list
21st Sep 2019, 12:17 PM
Mohamed Rashidey Hasan
Mohamed Rashidey Hasan - avatar