get list from Tkinter text field, check for duplicates and remove any












0















I am trying to clean a text field of its duplicate items (each item is on a new line in the text field). My logic: call get() on the text field, insert into a list, and then run an admittedly slow series of nested loops to check for duplicates and then repopulate the text field.



Could someone please help evaluate my logic and tell me why this isn't working?



def checkDup(self):
clean =
dirty = O1.get("1.0", END+'-1c').split("n")
for i in dirty[1:]:
if i not in clean:
clean.append(i)
clean.append("n")
O1.delete("1.0", END)
O1.insert(END, clean)









share|improve this question

























  • This is not a minimal, complete and verifiable example. Please read this article and edit accordingly.

    – Ethan Field
    Nov 16 '18 at 14:24


















0















I am trying to clean a text field of its duplicate items (each item is on a new line in the text field). My logic: call get() on the text field, insert into a list, and then run an admittedly slow series of nested loops to check for duplicates and then repopulate the text field.



Could someone please help evaluate my logic and tell me why this isn't working?



def checkDup(self):
clean =
dirty = O1.get("1.0", END+'-1c').split("n")
for i in dirty[1:]:
if i not in clean:
clean.append(i)
clean.append("n")
O1.delete("1.0", END)
O1.insert(END, clean)









share|improve this question

























  • This is not a minimal, complete and verifiable example. Please read this article and edit accordingly.

    – Ethan Field
    Nov 16 '18 at 14:24
















0












0








0








I am trying to clean a text field of its duplicate items (each item is on a new line in the text field). My logic: call get() on the text field, insert into a list, and then run an admittedly slow series of nested loops to check for duplicates and then repopulate the text field.



Could someone please help evaluate my logic and tell me why this isn't working?



def checkDup(self):
clean =
dirty = O1.get("1.0", END+'-1c').split("n")
for i in dirty[1:]:
if i not in clean:
clean.append(i)
clean.append("n")
O1.delete("1.0", END)
O1.insert(END, clean)









share|improve this question
















I am trying to clean a text field of its duplicate items (each item is on a new line in the text field). My logic: call get() on the text field, insert into a list, and then run an admittedly slow series of nested loops to check for duplicates and then repopulate the text field.



Could someone please help evaluate my logic and tell me why this isn't working?



def checkDup(self):
clean =
dirty = O1.get("1.0", END+'-1c').split("n")
for i in dirty[1:]:
if i not in clean:
clean.append(i)
clean.append("n")
O1.delete("1.0", END)
O1.insert(END, clean)






python tkinter get duplicates






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 14:22









Ethan Field

2,51811429




2,51811429










asked Nov 16 '18 at 2:48









Philippe MamanPhilippe Maman

6




6













  • This is not a minimal, complete and verifiable example. Please read this article and edit accordingly.

    – Ethan Field
    Nov 16 '18 at 14:24





















  • This is not a minimal, complete and verifiable example. Please read this article and edit accordingly.

    – Ethan Field
    Nov 16 '18 at 14:24



















This is not a minimal, complete and verifiable example. Please read this article and edit accordingly.

– Ethan Field
Nov 16 '18 at 14:24







This is not a minimal, complete and verifiable example. Please read this article and edit accordingly.

– Ethan Field
Nov 16 '18 at 14:24














1 Answer
1






active

oldest

votes


















0














I would have used the same logic with for loops for checking duplicates.. maybe there is something better out there to do that but for now at our level I think it's a good start.



reviewing your code:



for i in dirty[1:]: 


Here why do you start after the first item in your list, does it need to be excluded? if so, you are deleting it anyways with:



01.delete('1.0', END)


You may need to change your code to 01.delete('2.0', END) if you need to keep the first line.



if i not in clean:
clean.append(i)
clean.append('n')


Here, you are creating a longer list with a bunch of newlines that are each considered a member of your list, interesting.. I messed up with this portion.. after testing I see your results are only half as weird as what I did.



last line: you are pushing your corrected list directly in your widget, which causes a weird result.



01.insert(END, clean)


Fix that one this way; 01.insert(END, ''.join(clean)) this will break your list into a string containing your previously inserted newlines, putting all the text in the right place.






share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53330720%2fget-list-from-tkinter-text-field-check-for-duplicates-and-remove-any%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I would have used the same logic with for loops for checking duplicates.. maybe there is something better out there to do that but for now at our level I think it's a good start.



    reviewing your code:



    for i in dirty[1:]: 


    Here why do you start after the first item in your list, does it need to be excluded? if so, you are deleting it anyways with:



    01.delete('1.0', END)


    You may need to change your code to 01.delete('2.0', END) if you need to keep the first line.



    if i not in clean:
    clean.append(i)
    clean.append('n')


    Here, you are creating a longer list with a bunch of newlines that are each considered a member of your list, interesting.. I messed up with this portion.. after testing I see your results are only half as weird as what I did.



    last line: you are pushing your corrected list directly in your widget, which causes a weird result.



    01.insert(END, clean)


    Fix that one this way; 01.insert(END, ''.join(clean)) this will break your list into a string containing your previously inserted newlines, putting all the text in the right place.






    share|improve this answer






























      0














      I would have used the same logic with for loops for checking duplicates.. maybe there is something better out there to do that but for now at our level I think it's a good start.



      reviewing your code:



      for i in dirty[1:]: 


      Here why do you start after the first item in your list, does it need to be excluded? if so, you are deleting it anyways with:



      01.delete('1.0', END)


      You may need to change your code to 01.delete('2.0', END) if you need to keep the first line.



      if i not in clean:
      clean.append(i)
      clean.append('n')


      Here, you are creating a longer list with a bunch of newlines that are each considered a member of your list, interesting.. I messed up with this portion.. after testing I see your results are only half as weird as what I did.



      last line: you are pushing your corrected list directly in your widget, which causes a weird result.



      01.insert(END, clean)


      Fix that one this way; 01.insert(END, ''.join(clean)) this will break your list into a string containing your previously inserted newlines, putting all the text in the right place.






      share|improve this answer




























        0












        0








        0







        I would have used the same logic with for loops for checking duplicates.. maybe there is something better out there to do that but for now at our level I think it's a good start.



        reviewing your code:



        for i in dirty[1:]: 


        Here why do you start after the first item in your list, does it need to be excluded? if so, you are deleting it anyways with:



        01.delete('1.0', END)


        You may need to change your code to 01.delete('2.0', END) if you need to keep the first line.



        if i not in clean:
        clean.append(i)
        clean.append('n')


        Here, you are creating a longer list with a bunch of newlines that are each considered a member of your list, interesting.. I messed up with this portion.. after testing I see your results are only half as weird as what I did.



        last line: you are pushing your corrected list directly in your widget, which causes a weird result.



        01.insert(END, clean)


        Fix that one this way; 01.insert(END, ''.join(clean)) this will break your list into a string containing your previously inserted newlines, putting all the text in the right place.






        share|improve this answer















        I would have used the same logic with for loops for checking duplicates.. maybe there is something better out there to do that but for now at our level I think it's a good start.



        reviewing your code:



        for i in dirty[1:]: 


        Here why do you start after the first item in your list, does it need to be excluded? if so, you are deleting it anyways with:



        01.delete('1.0', END)


        You may need to change your code to 01.delete('2.0', END) if you need to keep the first line.



        if i not in clean:
        clean.append(i)
        clean.append('n')


        Here, you are creating a longer list with a bunch of newlines that are each considered a member of your list, interesting.. I messed up with this portion.. after testing I see your results are only half as weird as what I did.



        last line: you are pushing your corrected list directly in your widget, which causes a weird result.



        01.insert(END, clean)


        Fix that one this way; 01.insert(END, ''.join(clean)) this will break your list into a string containing your previously inserted newlines, putting all the text in the right place.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 16 '18 at 10:10

























        answered Nov 16 '18 at 9:30









        Dave MaheuxDave Maheux

        329312




        329312
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53330720%2fget-list-from-tkinter-text-field-check-for-duplicates-and-remove-any%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Florida Star v. B. J. F.

            Error while running script in elastic search , gateway timeout

            Adding quotations to stringified JSON object values