Here’s another option:
s="some string"
numbers = sum(c.isdigit() for c in s)
letters = sum(c.isalpha() for c in s)
spaces = sum(c.isspace() for c in s)
others = len(s) - numbers - letters - spaces
More Related Contents:
- Why is it string.join(list) instead of list.join(string)?
- How to convert string representation of list to a list?
- How to find all occurrences of a substring?
- Process escape sequences in a string in Python
- Why does substring slicing with index out of range work?
- Comparing a string to multiple items in Python
- Calculate cosine similarity given 2 sentence strings
- Join a list of items with different types as string in Python
- How to convert string to binary?
- ‘str’ object does not support item assignment
- Split a string at uppercase letters
- How can I print variable and string on same line in Python?
- python replace single backslash with double backslash
- Python float – str – float weirdness
- Easy way of finding decimal places
- How do I split the definition of a long string over multiple lines?
- Find the item with maximum occurrences in a list [duplicate]
- formatting long numbers as strings in python
- What is the difference between encode/decode?
- How do I write data into CSV format as string (not file)?
- How to create a numpy array of arbitrary length strings?
- How to write very long string that conforms with PEP8 and prevent E501
- Remove ‘b’ character do in front of a string literal in Python 3 [duplicate]
- Capitalize a string
- Python regex: splitting on pattern match that is an empty string
- How to decode a video (memory file / byte string) and step through it frame by frame in python?
- How to create raw string from string variable in python?
- What does backward-slash b do in Python?
- Sort strings by the first N characters
- How to pad a string to a fixed length with spaces [duplicate]