Python Program to Remove Duplicate Elements from a List

Поделиться
HTML-код
  • Опубликовано: 5 сен 2024
  • In this tutorial you will learn to write a Python Program to Remove Duplicate Elements from a List.
    The function that we create here will take a list which as duplicate elements as a parameter and it will return a list without any duplicates.
    our Social Media Pages
    / exampleprogram
    / exampleprogram
    / example_program
    Our Website
    www.ExamplePro...
    #ExampleProgram

Комментарии • 77

  • @mayank9447
    @mayank9447 3 года назад +19

    You made your code so complex you could just convert the list to sets and all duplicates would be gone

    • @vickyrocks6560
      @vickyrocks6560 3 года назад +1

      excellent bro

    • @moodmaker2796
      @moodmaker2796 2 года назад

      To be fair: I am a beginner and I new about the x2 = list(set(x)) method but I thought I needed to figure out problem solving shit... not thinking once about the possibility of a "not in" statement... so I came here and was enlightened... only to forget it in two days haha.
      Doing shit the hard way can be very helpful to learn the basics I guess.

    • @sktdebnath
      @sktdebnath 2 года назад

      This is exactly what I did. But you will mess up the order. So you have to sort according to the list index.

    • @deepaksankhua7791
      @deepaksankhua7791 2 месяца назад

      Yeah

  • @fredsoda3034
    @fredsoda3034 3 года назад +2

    Thank you. I appreciate your Support for the Community.

  • @mR_r0b07
    @mR_r0b07 3 года назад +8

    Thanks sire u helped me solve my assignment 🇳🇬💗💗

  • @sanjaychanghate8898
    @sanjaychanghate8898 3 года назад +3

    Thanks sire u helped me a lot😘😘😘

  • @pennywise6058
    @pennywise6058 3 года назад +8

    Bro u put that duplicate list into set datatype and you again convert the set to the list data type and print the list like this
    List1=[ 1,5,6,4,2,3,3,3]
    Set1=set(list1)
    List1= list(set1)
    Print(list1)

    • @prasanna4280
      @prasanna4280 2 года назад

      Yes..
      Friend i have another doubt in .py
      If we want to find index of second occurrence of a number in list what we do.. ans need urgent

  • @ammadammad4709
    @ammadammad4709 2 года назад +6

    Can we count the duplicate numbers In a list without using count built-in function?
    I want an output like...
    (Number, repeated x times)

  • @Adrian.LovesFitness
    @Adrian.LovesFitness 3 года назад +1

    YOU SAVED MY LIFE!!!!!!!

  • @lindsay9120
    @lindsay9120 3 года назад +2

    thank you, dawg. appreciate ya

  • @riadalhasanabir6716
    @riadalhasanabir6716 3 года назад +1

    thank you so much it solved my assignment

  • @siddigamer4426
    @siddigamer4426 Год назад +1

    Thank you very much>>>...

  • @susantaVlogs180
    @susantaVlogs180 3 года назад +5

    for loop would be performance killer if we have a big list...

    • @Davidkunde
      @Davidkunde 2 года назад

      list comprehension will come in handy in this case

  • @sinengazzah5528
    @sinengazzah5528 2 года назад +1

    i swear i love u bro

  • @Abhishekkumar-fi1dy
    @Abhishekkumar-fi1dy 3 года назад +1

    This is really helpful

  • @gianlucacaredda5202
    @gianlucacaredda5202 3 года назад +1

    I am trying to print also the noduplist by the console tells me that it is not defined. What should I do ??

  • @AttachmentStudios
    @AttachmentStudios Год назад +1

    Use this rather maybe if you wanna reduce lines of code:
    # Function
    remove_duplicates = lambda input_list:list(dict({key:0 for key in input_list}))
    # Example/Usage
    my_list = [...]
    my_list = remove_duplicates(my_list)

  • @majjigurunadh6108
    @majjigurunadh6108 2 месяца назад +1

    Tq Sir

  • @flipaclip-animators6455
    @flipaclip-animators6455 3 года назад +1

    Nice work

  • @hotroadcol4166
    @hotroadcol4166 3 года назад +1

    Thanks

  • @rajeswaranr9082
    @rajeswaranr9082 3 года назад +1

    Awsm❤️

  • @HarshaMaddur
    @HarshaMaddur 3 года назад +3

    Please correct me if I am wrong. Why complicating things by defining function. Why not this following simple code:
    data=[10, 20, 30, 30, 40, 50, 50, 60, 70]
    noduplist=[]
    for element in data:
    if element not in noduplist:
    noduplist.append(element)

    print(noduplist)
    #output: [10, 20, 30, 40, 50, 60, 70]

    • @abrarulhasan3602
      @abrarulhasan3602 3 года назад

      totally agree

    • @HarshaMaddur
      @HarshaMaddur 3 года назад

      @Prashant Rai Ok. Thank you.

    • @KILLER-kt9no
      @KILLER-kt9no 3 года назад

      good one bro!

    • @ShubhamRai06
      @ShubhamRai06 3 года назад

      by defining function we can , use it any no of time with any no of duplicate list , that's what functions are use for...

    • @rohitsinghrawat6317
      @rohitsinghrawat6317 2 года назад

      print(list(set(data))) try this

  • @carlfernandez9897
    @carlfernandez9897 Год назад

    Can't you sort it, loop through the array comparing it to the last element and if so delete that that element/append it if not, to a noduplist. Then it sorts in nlog(n) time and runs in n time. This will run in worst case (n/2)^2. which is worse after 8 elements.

  • @escapefelicity2913
    @escapefelicity2913 Год назад +1

    It might be a REAL GOOD IDEA to post the code

    • @ExampleProgram
      @ExampleProgram  Год назад

      thanks for the suggestion.
      i will try to implement that :)

  • @mohammadaslam5815
    @mohammadaslam5815 2 года назад +1

    Sir pls.. say sir
    Noduplist is a empty list
    But how we check if the element present in noduplist or not...

    • @sahilhanda6761
      @sahilhanda6761 Год назад

      See what happens is we iterate over the new list and if for example '0' is there in list , program will not execute. Therefore 'not in' is used

  • @GladwinNewton
    @GladwinNewton 2 года назад

    Thank you

  • @cedar693
    @cedar693 3 года назад +2

    when I heard an Indian accent I knew, I'd learn something today.

  • @06_shubhambirhade81
    @06_shubhambirhade81 3 года назад +1

    This program question is asked in every interview

  • @mymantra4
    @mymantra4 3 года назад +2

    We can convert the list into set to remove duplicates

  • @timechannel5850
    @timechannel5850 2 года назад

    but how to remove duplicate with that number for example numbers=[2,2,4,4,6,8,8,9] it will be unique =[6,9] . how to solve that problem?

  • @sumitbhoi4070
    @sumitbhoi4070 3 года назад

    For elements in duplist likhna jaruri hai kya ?

  • @RohitRaj-nt9ot
    @RohitRaj-nt9ot 2 года назад

    It's not working in my system. Error says function object not iterable

  • @concisejellyfish
    @concisejellyfish 2 года назад +1

    nice

  • @alfonsoramirezelorriaga1153
    @alfonsoramirezelorriaga1153 2 года назад +2

    It would be great if you could show how to do it withouth the "not in" method. That is what I am trying to do. I am trying to loop through "unique" and if "i" is not equal to "j" then I append i to unique. However, I am doing something wrong sintaxis wise.

  • @vashistathakuri8026
    @vashistathakuri8026 2 года назад +1

    You can just convert it to a set and convert it back to a list.

  • @telugughostloverskaadda2163
    @telugughostloverskaadda2163 Год назад

    Please tell me how to remove alternative eliminats in a list

  • @kvelez
    @kvelez 11 месяцев назад

    data = [10,20,20,30,40,50,50]
    def remove_duplicate(data, i):
    if i >= len(data):
    return data
    if isinstance(data[i], int):
    if data[i] == data[i+1]:
    data.pop(i)
    return remove_duplicate(data, i+1)
    print(remove_duplicate(data, 0))

  • @janardhanm3060
    @janardhanm3060 5 месяцев назад +1

  • @karisamichael2417
    @karisamichael2417 2 года назад

    Nice video but...?
    How do you delete the '+' in the list below?
    My_list=[+1222..., +1838..., 1737...]

  • @areebtahir2692
    @areebtahir2692 3 года назад

    Sir ye har value ke liye kam nhi krega.
    While loop se krye ek baar

  • @hotroadcol4166
    @hotroadcol4166 3 года назад +1

    👍👍👍

  • @lostfrequency89
    @lostfrequency89 3 года назад

    Is this even efficient?

  • @AnilKumar-wf7lb
    @AnilKumar-wf7lb 2 года назад

    Sir what is the output for 1-2,2-3,3-4,4-5

  • @VeebaSauce
    @VeebaSauce Год назад

    Your explanation is not to the point.
    Can't understand what are saying.

  • @user-uc9nr6jl4g
    @user-uc9nr6jl4g Год назад

    This program is wrong