-
|
def list_count_z(list): count = 0 for list in list: if list == 'z': count = count + 1 print("z") return count you can do it like this and there is more option search it i have a large list like this ['z','z','z','z','e','e','e','z','z'] i want to print '4z3e2z' help please |
Beta Was this translation helpful? Give feedback.
-
|
def print_character_counts(lst):
char_count = {}
result = []
for char in lst:
char_count[char] = char_count.get(char, 0) + 1
for char, count in char_count.items():
result.append(f"{count}{char}")
print("".join(result))
# Example usage:
my_list = ['z', 'z', 'z', 'z', 'e', 'e', 'e', 'z', 'z']
print_character_counts(my_list) # Output: 4z3e2z
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
{{title}}
Uh oh!
There was an error while loading. Please reload this page.
-
i have a large list like this ['z','z','z','z','e','e','e','z','z']
i want to print '4z3e2z'
help please
Beta Was this translation helpful? Give feedback.