Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

i have a large list like this ['z','z','z','z','e','e','e','z','z'] i want to print '4z3e2z' help please #55

vkp3803 started this conversation in Ideas
Discussion options

i have a large list like this ['z','z','z','z','e','e','e','z','z']
i want to print '4z3e2z'
help please

You must be logged in to vote

Replies: 2 comments

Comment options

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

You must be logged in to vote
0 replies
Comment options

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
You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /