حذف تکراری های آرایه
تابعی بنویسید که یک لیست (آرایه) به عنوان پارامتر دریافت کند، و آیتم های تکراری آن را حذف کند و لیست (آرایه) جدید را برگرداند
👨💻 1 ساعت قبل کاربر ناشناس این تمرین رو مشاهده کرد
تابعی بنویسید که یک لیست (آرایه) به عنوان پارامتر دریافت کند، و آیتم های تکراری آن را حذف کند و لیست (آرایه) جدید را برگرداند
def x(i):
new_list = set(i)
finall = list(new_list)
return finall
l = [2, 4, 4, 4, 3, 6, 7, 9, 7, 8, 7, 0]
print(x(l))
def remov_duplicate(list : list):
remov_duplicate_list = []
for i in list:
if i in remov_duplicate_list:
pass
else :
remov_duplicate_list.append(i)
remov_duplicate_list.sort()
return remov_duplicate_list
my_list = [1,2,3,6,3,1,4,7,8,9,9,3,1,2]
print(f'duplicate list : {my_list}')
print(f'remov duplicate list : {remov_duplicate(my_list)}')
def remove_duplicates(input_list):
# استفاده از مجموعه برای حذف تکراریها
unique_items = set(input_list)
# تبدیل مجموعه به لیست و برگرداندن آن
return list(unique_items)
# مثال استفاده
original_list = [1, 2, 3, 2, 4, 1, 5, 3]
new_list = remove_duplicates(original_list)
print("لیست اصلی:", original_list)
print("لیست بدون تکراری:", new_list)
def remove_duplicates(my_list):
new_list = []
for item in my_list:
if item not in new_list:
new_list.append(item)
return new_list
numbers = [1, 2, 3, 2, 4, 1, 5, 3]
result = remove_duplicates(numbers)
print(result)
def lists(value):
b = set(my_list)
r = list(b)
return r
my_list = []
while True:
x = input('element: ')
if x == "": break
my_list.append(x)
print(lists(my_list))
def remove_duplicates(x):
return list(set(x))
text=input("please enter text here:")
print(remove_duplicates(text))
# Remove duplicate list items
def remove_duplicates(lst):
result = []
for item in lst:
if item not in result:
result.append(item)
return result
items = []
print("Enter values (enter . to finish):")
while True:
value = input()
if value == ".":
break
try:
items.append(int(value))
except ValueError:
items.append(value)
print(remove_duplicates(items))
araye = []
while True:
i = input('enter item list: ')
if i == '':
break
else:
araye.append(i)
def item(lst):
lst = list(set(lst))
return lst
print(item(araye))
```def remove_duplicates(my_list):
new_list = []
for item in my_list:
if item not in new_list:
new_list.append(item)
return new_list
print(remove_duplicates([1, 2, 2, 3, 1]))
```
```def remove_duplicates(my_list):
new_list = []
for item in my_list:
if item not in new_list:
new_list.append(item)
return new_list
print(remove_duplicates([1, 2, 2, 3, 1]))
```
جوابت را با Markdown بنویس و ثبت کن
برای استفاده از این بخش باید وارد حساب کاربریت بشی
ورود/ثبت نامتوضیح کوتاهی بنویسید تا تیم بررسی کند.