![]() |
VOOZH | about |
Let us see how to combine similar characters in a list.
Example :
Input : ['g', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'g', 'e', 'e', 'k', 's']
Output : ['gg', 'eeee', 'kk', 'ss', 'f', 'o', 'r']
We will be using the get() method of the dictionary class.
The get() method returns the value of the item with the specified key.
Syntax : dictionary.get(key name, value)
Parameters :
- keyname : The key name of the dictionary item.
- value : (Optional) If the specified key does not exist, then a value is returned.
Returns : Value of the item with the specified key
Algorithm :
Example 1 :
Output :
['gg', 'eeee', 'kk', 'ss', 'f', 'o', 'r']
Example 2 :
Output :
['a', 'h', 'i', 'l', 'n', 'oo', 'p', 'r', 'ttt', 'u', 'y']