-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
-
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.
All reactions
Replies: 2 comments
-
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.
All reactions
-
👍 3
0 replies
-
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.
All reactions
-
👍 1
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment