Frequency Stability Property | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Frequency Stability Property

Currently, I’m working on showing how the Frequency Stability Property works. The next step in my code involves the ability to select every three digits in each sequence, which I don’t know how to do. Below is a link to what I have so far: https://sololearn.com/compiler-playground/cG6UYv1rY4VY/?ref=app

26th Jun 2024, 3:51 PM
Annihilate
Annihilate - avatar
5 Answers
+ 2
or use list comprehension import random s1 = "".join(str(random.randint(0,1)) for _ in range(100)) print(s1) n = 3 grouped = [s1[i:i+n] for i in range(0,len(s1),n)] print(grouped) s2="".join("0" if random.random()<0.5 else "1" for _ in range(100)) print(s2) n = 3 grouped = [s2[i:i+n] for i in range(0,len(s2),n)] print(grouped)
26th Jun 2024, 4:40 PM
Bob_Li
Bob_Li - avatar
+ 1
import random import textwrap s1 = "".join(str(random.randint(0,1)) for _ in range(100)) print(s1) grouped = textwrap.wrap(s1,3) print(grouped)
26th Jun 2024, 4:26 PM
Bob_Li
Bob_Li - avatar
+ 1
Thanks, Bob_Li
27th Jun 2024, 2:49 PM
Annihilate
Annihilate - avatar
0
also, counting 1 and 0 can be simpler s1_zc = s1.count("0") s1_oc = 100 - s1_zc
26th Jun 2024, 11:59 PM
Bob_Li
Bob_Li - avatar
0
Any inbox numbers for chatting
27th Jun 2024, 8:45 PM
Estaine Award
Estaine Award - avatar