I’m pretty new to Mathematica and am stumped by this problem. I have a list that looks like this:
{{1, 1, 1}, {0}, {1}}
I want to replace each sublist with its first element. So, the above list should be converted to:
{1,0,1}
I’ve looked through the documentation repeatedly and Googled for hours. I’m sure that this is fairly simple, but I can’t figure it out. I started with this list:
{1, 1, 1, 0, 1}
I need to know how many runs of 1’s there are, which is obviously 2. So, I used Split to separate the list into groups of consecutive 1’s and 0’s. By using Length on this list I can get the total number of runs, which is 3. Now, I just need to calculate the number of runs of 1’s. If I can convert the list as mentioned above, I can just sum the items in the list to get the answer.
I hope that makes sense. Thanks for any help!
I’d do this:
or