- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
def removeSosedei(lst):
lst_new = []
for idx, item in enumerate(lst):
if idx == len(lst) - 1:
continue
if lst[idx] != lst[idx + 1]:
lst_new.append(item)
return lst_new
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
Всего: 6
−103
def removeSosedei(lst):
lst_new = []
for idx, item in enumerate(lst):
if idx == len(lst) - 1:
continue
if lst[idx] != lst[idx + 1]:
lst_new.append(item)
return lst_new
−103
#!/usr/bin/python
lst = [1,2,2,3,4,4,5,6,5,6]
lst_new = []
for idx, item in enumerate(lst):
if idx == len(lst) - 1:
continue
if lst[idx] != lst[idx + 1]:
lst_new.append(item)
print lst
print lst_new
−103
#!/usr/bin/python
lst = [1,2,2,3,4,4,5,6,5,6]
lst_new = []
for idx, item in enumerate(lst):
if idx == len(lst) - 1:
continue
if lst[idx] == lst[idx + 1]:
continue
lst_new.append(item)
print lst
print lst_new
−102
for idx, item in enumerate(lst):
print str(idx) + ": " + str(item)
−101
#!/usr/bin/python
lst = [1,2,2,3,4,4,5,6,5,6]
lst_new = []
for idx, item in enumerate(lst):
if idx == len(lst) - 1:
continue
if lst[idx] == lst[idx + 1]:
continue
lst_new.append(item)
print lst
print lst_new
−111
#!/usr/bin/python
lst = [1,2,2,3,4,4,5,6,5,6]
lst_new = []
for (counter, i) in enumerate(lst):
if counter != len(lst) - 1:
if lst[counter] == lst[counter+1]:
continue
if counter != 0:
if lst[counter] == lst[counter-1]:
continue
lst_new.append(i)
print lst
print lst_new