Skip to content


Folders and files

Last commit message
Last commit date

Latest commit



19 Commits

Repository files navigation

Self-Descriptive Sentence

A self-descriptive sentence generator. Targeting on any languages.


What is a self-descriptive sentence?

Self-descriptive sentence, aka. autogram, is a sentence that describes itself in the sense of providing an inventory of its own characters.

Here I'd like to show a famous example:

This sentence employs two a’s, two c’s, two d’s, twenty-eight e’s, five f’s, three g’s, eight h’s, eleven i’s, three l’s, two m’s, thirteen n’s, nine o’s, two p’s, five r’s, twenty-five s’s, twenty-three t’s, six v’s, ten w’s, two x’s, five y’s, and one z.

And another type:

T is the first, fourth, eleventh, sixteenth, ... letter in this sentence, not counting spaces or commas

For more information, please check the Wikipedia page of Autogram.


The purpose of this project is to build a program that could generate self-descriptive sentences.

As you may already known that there are several different types of self-descriptive (see above Wikipedia page). Here in this project I will firstly focus on the self-counting one. This kind of self-descriptive will present, for example, the total count of characters/words, the number of every single character/word, the number of every punctuation, and also the number of spaces if you want.

Also, I don't want to limit my program on English sentences only. It should work on different languages with minimal effort.

A Chinese self-counting sentence demo:

这个句子一共有七十五个字。其中有四个“十”;二个“子”;四个“三”;十二个“二”;二个“字”;一个“八”;三个“四”; 一个“六”;二个“七”;二个“中”;二个“其”;二个“共”;二个“这”;二个“句”;五个“一”;二十二个“个”;三个“有”; 一个“九”;三个“五”。

Program Usage

usage: self_descriptive_sentence [-h] [-v] [-l {chinese,number}]
                                 [-a ATTEMPTS] [-i ITERATIONS] [-V]
                                 [-0 | -1 | -s SEED]

Self-Descriptive Sentence Generator

positional arguments:
  text                  a text will be included in the sentence (default: )

optional arguments:
  -h, --help            show this help message and exit
  -v, --version         show program's version number and exit
  -l {chinese,number}, --language {chinese,number}
                        choose a language to generate sentence (default:
  -a ATTEMPTS, --attempts ATTEMPTS
                        the maximum number of attempts (default: 20)
  -i ITERATIONS, --iterations ITERATIONS
                        the maximum number of iterations in each attempt
                        (default: 300)
  -V, --no-verbose      disable debug messages (default: False)
  -0, --down-to-zero    prefer zero when performing a decrease operation on a
                        count=2 character (default: False)
  -1, --down-to-one     prefer one when performing a decrease operation on a
                        count=2 character (default: False)
  -s SEED, --seed SEED  use a seeded Random object to randomly choose between
                        zero and one when performing a decrease operation on a
                        count=2 character (default: None)


python self_descriptive_sentence -V:


python self_descriptive_sentence -V 我写的这句话:


python self_descriptive_sentence -V -l number 1:

1 employs 11 digits, 4 1's, 3 2's, 2 3's, 2 4's.

python self_descriptive_sentence -V -l number 123:

123 employs 17 digits, 4 1's, 4 2's, 2 3's, 4 4's, 1 6's, 2 7's.


A self-descriptive sentence generator. Targeting on any languages.







No packages published