duplicate list python code example
Example 1: copy a list python
new_list = old_list.copy()
new_list = old_list[:]
Example 2: duplicate in list python
a = [1,2,3,2,1,5,6,5,5,5]
import collections
print([item for item, count in collections.Counter(a).items() if count > 1])
Example 3: create copy of an array python
new_list = list.copy()
Example 4: python copy list
a=[1,2,3,4]
b=a[:]
''' now b has all elements of a'''
Example 5: python duplicate list elements
def duplicate_list_elements(_list : list):
duplicated_list = []
for element in _list:
duplicated_list.append(element)
duplicated_list.append(element)
return duplicated_list