![]() |
|
[Python] Remove duplicate lines from txt file? QUICK - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [Python] Remove duplicate lines from txt file? QUICK (/showthread.php?tid=5606183) |
Remove duplicate lines from txt file? QUICK - Woes - Apr 22, 2017 I googled this, seems simple af, but i'm trying some of the code and none of it is working, and I don't really feel like thinking it out.
Can somebody shoot me some code that works. Thanks! * - (╯°□°)╯︵ ┻━━┻ - Apr 22, 2017 http://stackoverflow.com/questions/1215208/how-might-i-remove-duplicate-lines-from-a-file * - PrivateDonut - Apr 22, 2017 Do you need the actual code? Because I know of a website that will remove duplicate lines. * - CaptainBlack - Apr 22, 2017 PHP Code Or simply use a set, sets in Python don't allow duplications: PHP Code * - systx - Apr 23, 2017 Quick and easy way that works perfectly... PHP Code * - SIM-1866423 - Apr 23, 2017 Well everyone seems like agree on same thing use set function coz its built-in function. * - .kr. - Apr 23, 2017 Code #!/usr/bin/python* - TheWarOwl - Apr 23, 2017 Here's a simple solution - store all of the new lines into a list and use set: PHP Code Then you can simply write over the old file or create a new one! PHP Code There are more simple solutions and one liners, however I want you to understand the process the best you can so I've expanded it for you. 🤝 * - RyanR45 - May 1, 2017 (Apr 22, 2017 07:24 PM)Woes Wrote: Hey can you PM me please I have a question about your services * - Goodies - May 1, 2017 This would be a way to do it with the least amount of code. It also assumes that order is not important. PHP Code Test file: Code this is a testCode >>> unique_lines("lol.txt") |