+ 1
make a group of lists...
Write a piece of code which will make a group of lists from a given list that each of them contains elements from the original list with the same first character. Example: if the given list is [āaliā, āappleā, āanathemaā, ābeeā, ābozā, ākafkaā] then result is [[āaliā, āappleā, āanathemaā], [ābeeā, ābozā], [ākafkaā]]
2 Answers
+ 1
source = [
'apple', 'apricot', 'berry', 'banana']
destination = []
for letter in 'abcdefghijklmnopqrstuvwxyz':
tmp = [element for element in
source if
element.startswith(letter)]
if tmp:
destination.append(tmp)
0
What have you tried so far?