Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How does Python calculate the number of occurrences of each character

Shulou Source: shulou.com Published: 2022-05-31 13:37:26 09月17日 Update

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!

Tags: Character number two P.F learning code content string test output between function name dot uppercase letters that is ideas situations Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Apple Shulou Information vpn Shulou Technology