Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does Python calculate the number of occurrences of each character

2025-03-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "how Python calculates the number of occurrences of each character". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how Python calculates the number of occurrences of each character".

1. Calculates the number of occurrences of each character and returns it as a list of tuples in the order in which it appears.

For example, I give you a string "abracadabra", and the strings in the statistics are output in the following format:

Ordered_count ("abracadabra") = [('aural, 5), (' baked, 2), ('ringing, 2), (' cantilevered, 1), ('dumbbell, 1)]

Problem solving code:

Def ordered_count (input): pass

Test case:

Ordered_count ("abracadabra") = [('aural, 5), (' baked, 2), ('ringing, 2), (' centering, 1), ('dumped, 1)] ordered_count ("Code Wars") = [(' Clearing, 1), ('Code Wars, 1), (' eBay, 1), ('', 1), ('Warrior, 1), (' ajar, 1) " ('ringing, 1), (' sworn, 1)]

two。 Write a function that converts the name to an abbreviation. This kata strictly uses two words, and there must be a space between them. The output should be two uppercase letters separated by dots.

It should look like this:

Sam Harris = > S.H

Patrick Feeney = > P.F

Problem solving code:

Def abbrevName (name): # code away!

Test case:

AbbrevName ("Sam Harris") = > "S.H" abbrevName ("Patrick Feenan") = > "P.F" abbrevName ("Evan Cole") = > "E.C" abbrevName ("P Favuzzi") = > "P.F" abbrevName ("David Mendieta") = > "D.M" Thank you for reading. This is the content of "how Python calculates the number of occurrences of each character". After the study of this article, I believe you have a deeper understanding of how Python calculates the number of occurrences of each character, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report