0
Help me I should get this as output. Group 1: ['Alice', 'Bob'] Group 2: ['Charlie', 'David'] Group 3: ['Eve', 'Frank']
players = ["Alice", "Bob", "Charlie", "David", "Eve", "Frank"] #Create 3 lists with 2 players each #Use slicing to create a list for Group 1 g1 = #Use slicing to create a list for Group 2 g2 = #Use slicing to create a list for Group 3 g3 = print("Group 1:") #display the 1st group print("Group 2:") #display the 2nd group print("Group 3:") #display the 3rd group
2 Respuestas
+ 2
Where is your code?
+ 2
The list has 6 elements. Each of them has an index, starting from 0.
So Alice is index 0.
A slice takes a part (segment) of the list, according to their index.
list[x:y] means all the elements starting with index of x, but less than y.
So to take the first two elements, you can do
players[0:2]
or you can also omit the zero in this case, simplified to
players[:2]
Go from here.