In this article we study lossless compression of strings of pure quantum states of indeterminate-length quantum codes which were introduced by Schumacher and Westmoreland. Past work has assumed that the strings of quantum data are prepared to be encoded in an independent and identically distributed way. We introduce the notion of quantum stochastic ensembles, allowing us to consider strings of quantum states prepared in a general way. For any quantum stochastic ensemble we define an associated quantum dynamical system and prove that the optimal average codeword length via lossless coding is equal to the quantum dynamical entropy of the associated quantum dynamical system. Date: August 6, 2019. 2010 Mathematics Subject Classification. Primary: 81P45. Secondary: 81P70, 94A15, 37A35 . Key words and phrases. Kraft-McMillan inequality, quantum dynamical system, quantum Markov chain, quantum dynamical entropy.