Some snakes, like king snakes for example, are extremely cannibalistic and will eat any other snake, including ones that larger than them.
Although rarer than with other snakes, ball pythons have at times been known to be cannibalistic. A ball python may try to eat another ball python if that ball python is smaller than itself. Therefore, housing one small ball python and one large ball python together is an extremely bad idea, as the larger one very well may try to eat the smaller of the pair.
Housing two ball pythons of similar size is less hazardous, as the two will likely not try to eat each other if they are of similar size.
That being said, it’s normally a very bad idea to try housing two ball pythons together regardless of whether or not they will eat each other. Housing two ball pythons together will increase stress on both snakes, even if one does not try to eat the other. Increased stress often leads to ball pythons refusing to eat, and so housing the two snakes together may lead to both starving themselves. Furthermore, if one ball python contracts a sickness, since the majority of illnesses are contagious, it is very likely if the two are housed together that the other will also become sick. The best option is to have all ball pythons individually housed, so that none of these problems occur.