This section mainly achieves the following objectives:
1. Implement Python to get the most occurrences/fewer characters in a string
2. Analysis and treatment of existing problems
3. Optimization scheme
1. Implement Python to get the most occurrences/fewer characters in a string: 2. Problem analysis and Processing: Code Description:
The 1, max () method returns the maximum value for a given parameter, which can be a sequence. Refer to the Novice tutorial for details.
2. The Python count () method is used to count the number of occurrences of a character in a string. The optional parameters are the start and end positions of the string search. Refer to the Novice tutorial for details.
There is a problem with the code:
Issue1, the input string may be a full English character, or it may be a non-full English character. Examples include Chinese characters, numeric characters, special characters, and so on. In this case, Getmaxchar () will likely not return the expected value. Further optimization is required.
The value returned by Issue2, Getminchar, is often not the expected value. As in the example above, it is expected to return m, actually the value returned is B.
There is a problem root cause analysis:
The sequence of arguments given in the Issue1, Max method is the execution result of String.ascii_lowercase: ' ABCDEFGHIJKLMNOPQRSTUVWXYZ '. When the count () method is used, only the number of characters that exist in the sequence can be counted.
3, Optimization scheme optimization scheme 1: First to go to the weight, and then go to the heavy after the sequence as Max, min parameters.
Case: Chinese string
Case: Full word character
Case: All special characters
Case: Mixed character
"Python" Python Gets the most occurrences/fewer characters in a string