Evolution makes sense: parent organism spreads genes down to its children. But that's not the only way for genes to spread!
Genes can also spread horizontally to unrelated organisms! That's called Horizontal Gene Transfer. Bacteria do this all the time! The tiny animal shown here has 8% of genes borrowed from bacteria!
The Wikipedia page mentions a whole bunch of other examples of horizontal gene transfers:
- Small fish called smelts got the "antifreeze" gene from herrings
- Fruit flies have genes from bacteria
- Some fungi learned how to infect plants by getting the gene from plants!
https://en.wikipedia.org/wiki/Horizontal_gene_transfer#Eukaryotes
