1

I have a list with words out of different textfiles. When I sort this list out and clean them of duplicates I still see multiple words which are the soms but out of different text files, e.g. ['you', 'chainletter.txt'] and ['you', 'grail.txt'] My question is , how could I combine these to give the output ['you', 'chainletter.txt', 'grail.txt']

I'm currently using the following code: 'pearl' module:

def make_table(pairs):
    import sort
    import dup
    sort = sort.merge_pairs(pairs)
    nodup = dup.remove_dups(sort)
    print(nodup)
    return nodup

And i want my 'search engine' to display words like described above

James Bradbury
  • 1,708
  • 1
  • 19
  • 31
  • Note that when you do 'sort =', you're overwriting the imported module, sort. It might work, but calling your variables something that's already used will cause weird problems at some point. – James Bradbury Sep 11 '14 at 13:42

1 Answers1

0

I'm not quite sure what you're trying to achieve overall, but the two problems you mention can be solved as follows:

  1. You can use set() to remove duplicates from a list (and list() to turn it back into a list if you like).

  2. To add the elements of a list into another list, use .extend()

This question about merging lists may also be of interest.

Community
  • 1
  • 1
James Bradbury
  • 1,708
  • 1
  • 19
  • 31