How do I count the letters in Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch?

Like many problems to do with strings, this can be done in a simple way with a regex. >>> word = ‘Llanfairpwllgwyn|gyllgogerychwyrndrobwllllantysiliogogogoch’ >>> import re >>> pattern = re.compile(r’ch|dd|ff|ng|ll|ph|rh|th|[^\W\d_]’, flags=re.IGNORECASE) >>> len(pattern.findall(word)) 51 The character class [^\W\d_] (from here) matches word-characters that are not digits or underscores, i.e. letters, including those with diacritics.

Fast way of counting non-zero bits in positive integer

For arbitrary-length integers, bin(n).count(“1”) is the fastest I could find in pure Python. I tried adapting Óscar’s and Adam’s solutions to process the integer in 64-bit and 32-bit chunks, respectively. Both were at least ten times slower than bin(n).count(“1”) (the 32-bit version took about half again as much time). On the other hand, gmpy popcount() … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)