擅长:python、mysql、java
<p>不使用itertools的替代解决方案是:</p>
<pre><code>my_list = [3, 3, 3, 3, 3, 3, 100, 1, 1, 1, 1, 1, 1, 200, 3, 3, 3, 100, 1, 1, 1]
new_list = []
new_list.append(my_list[0]) #adding first element
count = 1 #variable for counting repeated elements
i = 1 #iterator through list
l = len(my_list)
while i < l:
while i < l and my_list[i] == my_list[i-1]:
count +=1
i+=1
if count > 1:
new_list.append(count)
count = 1 #returning to original default value
else:
new_list.append(my_list[i])
i+=1
print(new_list)
</code></pre>