Python မှ လုံး တစ် လုံး မှ ပြန်ရစ်ချက် အား ဖယ်ရှားခြင်း ဘာသာပြန်ချက်

Python မှ လုံး တစ် လုံး မှ ပြန်ရစ်ချက် အား ဖယ်ရှားခြင်း ဘာသာပြန်ချက် သတ္တုပတ်

实例

လုံး တစ် လုံး မှ ပြန်ရစ်ချက် အား ဖယ်ရှားခြင်း

mylist = ["a", "b", "a", "c", "c"]
mylist = list(dict.fromkeys(mylist))
print(mylist)

运行实例

အကျိုးဆက် ရှာဖွေခြင်း

ပြီးပြီးာပြီ ကျွန်တော် တွင် ပြန်ရစ်ချက် ပါရှိသော လုံး တစ် လုံး ရှိသည်:

ပြန်ရစ်ချက် ပါရှိသော လုံး တစ် လုံး

mylist = ["a", "b", "a", "c", "c"]
mylist = list(dict.fromkeys(mylist))
print(mylist)

လုံး တစ် လုံး အက်ဥပဒေ ကို လုံး တစ် လုံး အက်ဥပဒေ အဖြစ် ဖွဲ့စည်းခြင်းကို လုပ်ပေးသည်။ အက်ဥပဒေ မှ ပြန်ရစ်ချက် မရှိသေးသည်ကို အဆိုပါ ဖြစ်သည်ကို လုပ်ပေးသည်။ အက်ဥပဒေ မှ ပြန်ရစ်ချက် မရှိသေးသည်။

创建字典

mylist = ["a", "b", "a", "c", "c"]
mylist = list( dict.fromkeys(mylist) )
print(mylist)

နောက်တွင်၊ လုံး တစ် လုံး ကို အစားထိုး လုံး သို့ ပြောင်းလဲခြင်းလုပ်ပေးသည်:

လုံး တစ် လုံး သို့ ပြောင်းလဲခြင်း

mylist = ["a", "b", "a", "c", "c"]
mylist = list(dict.fromkeys(mylist)) 
print(mylist)

ယခု ကျွန်တော် တွင် မပြန်ရစ်ချက် မရှိသော နေရာစဉ် လုံး တစ် လုံး ရှိသည်။ အစားထိုး လုံး တစ် လုံး နှင့် အတူ ပြောင်းလဲခြင်း မရှိသည်။

打印列表以演示结果:

打印 List

mylist = ["a", "b", "a", "c", "c"]
mylist = list(dict.fromkeys(mylist))
print(mylist)

创建函数

如果您希望有一个函数可以发送列表,然后它们返回的无重复项,则可以创建函数并插入上例中的代码。

实例

def my_function(x):
  return list(dict.fromkeys(x))
mylist = my_function(["a", "b", "a", "c", "c"])
print(mylist)

运行实例

例子解释

创建一个以 List 作为参数的函数。

创建函数

def my_function(x): 
  return list(dict.fromkeys(x))
mylist = my_function(["a", "b", "a", "c", "c"])
print(mylist)

使用此 List 项作为键创建字典。

创建字典

def my_function(x):
  return list( dict.fromkeys(x) )
mylist = my_function(["a", "b", "a", "c", "c"])
print(mylist)

သုံးပြီးသတင်း

သုံးပြီးသတင်း

def my_function(x):
  return list( dict.fromkeys(x) ) 
mylist = my_function(["a", "b", "a", "c", "c"])
print(mylist)

သတင်းပို့ပြီ

သတင်းပို့ပြီ

def my_function(x):
  return list(dict.fromkeys(x))
mylist = my_function(["a", "b", "a", "c", "c"])
print(mylist)

သုံးပြီးသတင်း

သုံးပြီးသတင်း

def my_function(x):
  return list(dict.fromkeys(x))
mylist = my_function(["a", "b", "a", "c", "c"])
print(mylist)

သတင်းပို့ပြီ

သတင်းပို့ပြီ

def my_function(x):
  return list(dict.fromkeys(x))
mylist = my_function(["a", "b", "a", "c", "c"])
print(mylist)