how to sort by length of string followed by alphabetical order?











up vote
50
down vote

favorite
11












I'm currently new to python and got stuck at this question, can't seem to find the proper answer.



question:Given a list of words, return a list with the same words in order of length (longest to shortest), the second sort criteria should be alphabetical. Hint: you need think of two functions.



This is what I have so far:



def bylength(word1,word2):
return len(word2)-len(word1)

def sortlist(a):
a.sort(cmp=bylength)
return a


it sorts by length but I don't know how to apply the second criteria to this sort, which is by alphabetical descending.










share|improve this question




















  • 1




    stackoverflow.com/questions/4655591/python-sort-list - looks like a homework of a large classroom...
    – eumiro
    Jan 11 '11 at 15:56















up vote
50
down vote

favorite
11












I'm currently new to python and got stuck at this question, can't seem to find the proper answer.



question:Given a list of words, return a list with the same words in order of length (longest to shortest), the second sort criteria should be alphabetical. Hint: you need think of two functions.



This is what I have so far:



def bylength(word1,word2):
return len(word2)-len(word1)

def sortlist(a):
a.sort(cmp=bylength)
return a


it sorts by length but I don't know how to apply the second criteria to this sort, which is by alphabetical descending.










share|improve this question




















  • 1




    stackoverflow.com/questions/4655591/python-sort-list - looks like a homework of a large classroom...
    – eumiro
    Jan 11 '11 at 15:56













up vote
50
down vote

favorite
11









up vote
50
down vote

favorite
11






11





I'm currently new to python and got stuck at this question, can't seem to find the proper answer.



question:Given a list of words, return a list with the same words in order of length (longest to shortest), the second sort criteria should be alphabetical. Hint: you need think of two functions.



This is what I have so far:



def bylength(word1,word2):
return len(word2)-len(word1)

def sortlist(a):
a.sort(cmp=bylength)
return a


it sorts by length but I don't know how to apply the second criteria to this sort, which is by alphabetical descending.










share|improve this question















I'm currently new to python and got stuck at this question, can't seem to find the proper answer.



question:Given a list of words, return a list with the same words in order of length (longest to shortest), the second sort criteria should be alphabetical. Hint: you need think of two functions.



This is what I have so far:



def bylength(word1,word2):
return len(word2)-len(word1)

def sortlist(a):
a.sort(cmp=bylength)
return a


it sorts by length but I don't know how to apply the second criteria to this sort, which is by alphabetical descending.







python sorting






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 24 '12 at 22:46









Robert Harvey

147k33270415




147k33270415










asked Jan 11 '11 at 15:52









Adrian

2,00131312




2,00131312








  • 1




    stackoverflow.com/questions/4655591/python-sort-list - looks like a homework of a large classroom...
    – eumiro
    Jan 11 '11 at 15:56














  • 1




    stackoverflow.com/questions/4655591/python-sort-list - looks like a homework of a large classroom...
    – eumiro
    Jan 11 '11 at 15:56








1




1




stackoverflow.com/questions/4655591/python-sort-list - looks like a homework of a large classroom...
– eumiro
Jan 11 '11 at 15:56




stackoverflow.com/questions/4655591/python-sort-list - looks like a homework of a large classroom...
– eumiro
Jan 11 '11 at 15:56












4 Answers
4






active

oldest

votes

















up vote
100
down vote



accepted










You can do it in two steps like this:



the_list.sort() # sorts normally by alphabetical order
the_list.sort(key=len, reverse=True) # sorts by descending length


Python's sort is stable, which means that sorting the list by length leaves the elements in alphabetical order when the length is equal.



You can also do it like this:



the_list.sort(key=lambda item: (-len(item), item))


Generally you never need cmp, it was even removed in Python3. key is much easier to use.






share|improve this answer



















  • 2




    the lambda solution is awe-some!
    – dmeu
    Mar 18 '16 at 16:31


















up vote
5
down vote













n = ['aaa', 'bbb', 'ccc', 'dddd', 'dddl', 'yyyyy']

for i in reversed(sorted(n, key=len)):
print i



yyyyy dddl dddd ccc bbb aaa




for i in sorted(n, key=len, reverse=True):
print i



yyyyy dddd dddl aaa bbb ccc







share|improve this answer























  • This only works if the array is already sorted. Only sorted( sorted( iterable ), key=len ) gives the correct answer always.
    – user
    Jun 16 at 18:46












  • @user I just tried with unsorted array . Getting the same (correct) result . Can you please provide your input array ?
    – Arindam Roychowdhury
    Jun 18 at 7:36










  • sorted( ['bb', 'b', 'aa', 'a'], key=len, reverse=True) produces ['bb', 'aa', 'b', 'a'], but it should be ['aa', 'bb', 'a', 'b'] as get from sorted( sorted( ['bb', 'b', 'aa', 'a'] ), key=len, reverse=True)
    – user
    Jun 18 at 13:48


















up vote
1
down vote













-Sort your list by alpha order, then by length.

See the following exmple:

>>> coursesList = ["chemistry","physics","mathematics","art"]
>>> sorted(coursesList,key=len)
['art', 'physics', 'chemistry', 'mathematics']
>>> coursesList.append("mopsosa")
>>> sorted(coursesList,key=len)
['art', 'physics', 'mopsosa', 'chemistry', 'mathematics']
>>> coursesList.sort()
>>> sorted(coursesList,key=len)
['art', 'mopsosa', 'physics', 'chemistry', 'mathematics']





share|improve this answer




























    up vote
    0
    down vote













    Although Jochen Ritzel said you don't need cmp, this is actually a great use case for it! Using cmp you can sort by length and then alphabetically at the same time in half the time sorting twice would take!



    def cmp_func(a, b):
    # sort by length and then alphabetically in lowercase
    if len(a) == len(b):
    return cmp(a, b)
    return cmp(len(a), len(b))

    sorted_the_way_you_want = sorted(the_list, cmp=cmp_func)


    Example:



    >>> the_list = ['B', 'BB', 'AA', 'A', 'Z', 'C', 'D']
    >>> sorted(the_list, cmp=cmp_func)
    ['A', 'B', 'C', 'D', 'Z', 'AA', 'BB']


    Note, if your list is a mix of upper and lower case replace cmp(a, b) with cmp(a.lower(), b.lower()) as python sorts 'a' > 'Z'.



    In python3 you'd need to be sorting objects with __lt__ style comparison functions defined or functools.cmp_to_key() which does that for you.






    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',
      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%2f4659524%2fhow-to-sort-by-length-of-string-followed-by-alphabetical-order%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      4 Answers
      4






      active

      oldest

      votes








      4 Answers
      4






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      100
      down vote



      accepted










      You can do it in two steps like this:



      the_list.sort() # sorts normally by alphabetical order
      the_list.sort(key=len, reverse=True) # sorts by descending length


      Python's sort is stable, which means that sorting the list by length leaves the elements in alphabetical order when the length is equal.



      You can also do it like this:



      the_list.sort(key=lambda item: (-len(item), item))


      Generally you never need cmp, it was even removed in Python3. key is much easier to use.






      share|improve this answer



















      • 2




        the lambda solution is awe-some!
        – dmeu
        Mar 18 '16 at 16:31















      up vote
      100
      down vote



      accepted










      You can do it in two steps like this:



      the_list.sort() # sorts normally by alphabetical order
      the_list.sort(key=len, reverse=True) # sorts by descending length


      Python's sort is stable, which means that sorting the list by length leaves the elements in alphabetical order when the length is equal.



      You can also do it like this:



      the_list.sort(key=lambda item: (-len(item), item))


      Generally you never need cmp, it was even removed in Python3. key is much easier to use.






      share|improve this answer



















      • 2




        the lambda solution is awe-some!
        – dmeu
        Mar 18 '16 at 16:31













      up vote
      100
      down vote



      accepted







      up vote
      100
      down vote



      accepted






      You can do it in two steps like this:



      the_list.sort() # sorts normally by alphabetical order
      the_list.sort(key=len, reverse=True) # sorts by descending length


      Python's sort is stable, which means that sorting the list by length leaves the elements in alphabetical order when the length is equal.



      You can also do it like this:



      the_list.sort(key=lambda item: (-len(item), item))


      Generally you never need cmp, it was even removed in Python3. key is much easier to use.






      share|improve this answer














      You can do it in two steps like this:



      the_list.sort() # sorts normally by alphabetical order
      the_list.sort(key=len, reverse=True) # sorts by descending length


      Python's sort is stable, which means that sorting the list by length leaves the elements in alphabetical order when the length is equal.



      You can also do it like this:



      the_list.sort(key=lambda item: (-len(item), item))


      Generally you never need cmp, it was even removed in Python3. key is much easier to use.







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Jan 11 '11 at 15:58

























      answered Jan 11 '11 at 15:53









      Jochen Ritzel

      75.2k18153164




      75.2k18153164








      • 2




        the lambda solution is awe-some!
        – dmeu
        Mar 18 '16 at 16:31














      • 2




        the lambda solution is awe-some!
        – dmeu
        Mar 18 '16 at 16:31








      2




      2




      the lambda solution is awe-some!
      – dmeu
      Mar 18 '16 at 16:31




      the lambda solution is awe-some!
      – dmeu
      Mar 18 '16 at 16:31












      up vote
      5
      down vote













      n = ['aaa', 'bbb', 'ccc', 'dddd', 'dddl', 'yyyyy']

      for i in reversed(sorted(n, key=len)):
      print i



      yyyyy dddl dddd ccc bbb aaa




      for i in sorted(n, key=len, reverse=True):
      print i



      yyyyy dddd dddl aaa bbb ccc







      share|improve this answer























      • This only works if the array is already sorted. Only sorted( sorted( iterable ), key=len ) gives the correct answer always.
        – user
        Jun 16 at 18:46












      • @user I just tried with unsorted array . Getting the same (correct) result . Can you please provide your input array ?
        – Arindam Roychowdhury
        Jun 18 at 7:36










      • sorted( ['bb', 'b', 'aa', 'a'], key=len, reverse=True) produces ['bb', 'aa', 'b', 'a'], but it should be ['aa', 'bb', 'a', 'b'] as get from sorted( sorted( ['bb', 'b', 'aa', 'a'] ), key=len, reverse=True)
        – user
        Jun 18 at 13:48















      up vote
      5
      down vote













      n = ['aaa', 'bbb', 'ccc', 'dddd', 'dddl', 'yyyyy']

      for i in reversed(sorted(n, key=len)):
      print i



      yyyyy dddl dddd ccc bbb aaa




      for i in sorted(n, key=len, reverse=True):
      print i



      yyyyy dddd dddl aaa bbb ccc







      share|improve this answer























      • This only works if the array is already sorted. Only sorted( sorted( iterable ), key=len ) gives the correct answer always.
        – user
        Jun 16 at 18:46












      • @user I just tried with unsorted array . Getting the same (correct) result . Can you please provide your input array ?
        – Arindam Roychowdhury
        Jun 18 at 7:36










      • sorted( ['bb', 'b', 'aa', 'a'], key=len, reverse=True) produces ['bb', 'aa', 'b', 'a'], but it should be ['aa', 'bb', 'a', 'b'] as get from sorted( sorted( ['bb', 'b', 'aa', 'a'] ), key=len, reverse=True)
        – user
        Jun 18 at 13:48













      up vote
      5
      down vote










      up vote
      5
      down vote









      n = ['aaa', 'bbb', 'ccc', 'dddd', 'dddl', 'yyyyy']

      for i in reversed(sorted(n, key=len)):
      print i



      yyyyy dddl dddd ccc bbb aaa




      for i in sorted(n, key=len, reverse=True):
      print i



      yyyyy dddd dddl aaa bbb ccc







      share|improve this answer














      n = ['aaa', 'bbb', 'ccc', 'dddd', 'dddl', 'yyyyy']

      for i in reversed(sorted(n, key=len)):
      print i



      yyyyy dddl dddd ccc bbb aaa




      for i in sorted(n, key=len, reverse=True):
      print i



      yyyyy dddd dddl aaa bbb ccc








      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Mar 31 '17 at 0:53









      Ninjakannon

      2,66642645




      2,66642645










      answered Apr 15 '14 at 11:35









      Arindam Roychowdhury

      1,35032336




      1,35032336












      • This only works if the array is already sorted. Only sorted( sorted( iterable ), key=len ) gives the correct answer always.
        – user
        Jun 16 at 18:46












      • @user I just tried with unsorted array . Getting the same (correct) result . Can you please provide your input array ?
        – Arindam Roychowdhury
        Jun 18 at 7:36










      • sorted( ['bb', 'b', 'aa', 'a'], key=len, reverse=True) produces ['bb', 'aa', 'b', 'a'], but it should be ['aa', 'bb', 'a', 'b'] as get from sorted( sorted( ['bb', 'b', 'aa', 'a'] ), key=len, reverse=True)
        – user
        Jun 18 at 13:48


















      • This only works if the array is already sorted. Only sorted( sorted( iterable ), key=len ) gives the correct answer always.
        – user
        Jun 16 at 18:46












      • @user I just tried with unsorted array . Getting the same (correct) result . Can you please provide your input array ?
        – Arindam Roychowdhury
        Jun 18 at 7:36










      • sorted( ['bb', 'b', 'aa', 'a'], key=len, reverse=True) produces ['bb', 'aa', 'b', 'a'], but it should be ['aa', 'bb', 'a', 'b'] as get from sorted( sorted( ['bb', 'b', 'aa', 'a'] ), key=len, reverse=True)
        – user
        Jun 18 at 13:48
















      This only works if the array is already sorted. Only sorted( sorted( iterable ), key=len ) gives the correct answer always.
      – user
      Jun 16 at 18:46






      This only works if the array is already sorted. Only sorted( sorted( iterable ), key=len ) gives the correct answer always.
      – user
      Jun 16 at 18:46














      @user I just tried with unsorted array . Getting the same (correct) result . Can you please provide your input array ?
      – Arindam Roychowdhury
      Jun 18 at 7:36




      @user I just tried with unsorted array . Getting the same (correct) result . Can you please provide your input array ?
      – Arindam Roychowdhury
      Jun 18 at 7:36












      sorted( ['bb', 'b', 'aa', 'a'], key=len, reverse=True) produces ['bb', 'aa', 'b', 'a'], but it should be ['aa', 'bb', 'a', 'b'] as get from sorted( sorted( ['bb', 'b', 'aa', 'a'] ), key=len, reverse=True)
      – user
      Jun 18 at 13:48




      sorted( ['bb', 'b', 'aa', 'a'], key=len, reverse=True) produces ['bb', 'aa', 'b', 'a'], but it should be ['aa', 'bb', 'a', 'b'] as get from sorted( sorted( ['bb', 'b', 'aa', 'a'] ), key=len, reverse=True)
      – user
      Jun 18 at 13:48










      up vote
      1
      down vote













      -Sort your list by alpha order, then by length.

      See the following exmple:

      >>> coursesList = ["chemistry","physics","mathematics","art"]
      >>> sorted(coursesList,key=len)
      ['art', 'physics', 'chemistry', 'mathematics']
      >>> coursesList.append("mopsosa")
      >>> sorted(coursesList,key=len)
      ['art', 'physics', 'mopsosa', 'chemistry', 'mathematics']
      >>> coursesList.sort()
      >>> sorted(coursesList,key=len)
      ['art', 'mopsosa', 'physics', 'chemistry', 'mathematics']





      share|improve this answer

























        up vote
        1
        down vote













        -Sort your list by alpha order, then by length.

        See the following exmple:

        >>> coursesList = ["chemistry","physics","mathematics","art"]
        >>> sorted(coursesList,key=len)
        ['art', 'physics', 'chemistry', 'mathematics']
        >>> coursesList.append("mopsosa")
        >>> sorted(coursesList,key=len)
        ['art', 'physics', 'mopsosa', 'chemistry', 'mathematics']
        >>> coursesList.sort()
        >>> sorted(coursesList,key=len)
        ['art', 'mopsosa', 'physics', 'chemistry', 'mathematics']





        share|improve this answer























          up vote
          1
          down vote










          up vote
          1
          down vote









          -Sort your list by alpha order, then by length.

          See the following exmple:

          >>> coursesList = ["chemistry","physics","mathematics","art"]
          >>> sorted(coursesList,key=len)
          ['art', 'physics', 'chemistry', 'mathematics']
          >>> coursesList.append("mopsosa")
          >>> sorted(coursesList,key=len)
          ['art', 'physics', 'mopsosa', 'chemistry', 'mathematics']
          >>> coursesList.sort()
          >>> sorted(coursesList,key=len)
          ['art', 'mopsosa', 'physics', 'chemistry', 'mathematics']





          share|improve this answer












          -Sort your list by alpha order, then by length.

          See the following exmple:

          >>> coursesList = ["chemistry","physics","mathematics","art"]
          >>> sorted(coursesList,key=len)
          ['art', 'physics', 'chemistry', 'mathematics']
          >>> coursesList.append("mopsosa")
          >>> sorted(coursesList,key=len)
          ['art', 'physics', 'mopsosa', 'chemistry', 'mathematics']
          >>> coursesList.sort()
          >>> sorted(coursesList,key=len)
          ['art', 'mopsosa', 'physics', 'chemistry', 'mathematics']






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jun 15 '15 at 10:34









          jyfar

          392




          392






















              up vote
              0
              down vote













              Although Jochen Ritzel said you don't need cmp, this is actually a great use case for it! Using cmp you can sort by length and then alphabetically at the same time in half the time sorting twice would take!



              def cmp_func(a, b):
              # sort by length and then alphabetically in lowercase
              if len(a) == len(b):
              return cmp(a, b)
              return cmp(len(a), len(b))

              sorted_the_way_you_want = sorted(the_list, cmp=cmp_func)


              Example:



              >>> the_list = ['B', 'BB', 'AA', 'A', 'Z', 'C', 'D']
              >>> sorted(the_list, cmp=cmp_func)
              ['A', 'B', 'C', 'D', 'Z', 'AA', 'BB']


              Note, if your list is a mix of upper and lower case replace cmp(a, b) with cmp(a.lower(), b.lower()) as python sorts 'a' > 'Z'.



              In python3 you'd need to be sorting objects with __lt__ style comparison functions defined or functools.cmp_to_key() which does that for you.






              share|improve this answer

























                up vote
                0
                down vote













                Although Jochen Ritzel said you don't need cmp, this is actually a great use case for it! Using cmp you can sort by length and then alphabetically at the same time in half the time sorting twice would take!



                def cmp_func(a, b):
                # sort by length and then alphabetically in lowercase
                if len(a) == len(b):
                return cmp(a, b)
                return cmp(len(a), len(b))

                sorted_the_way_you_want = sorted(the_list, cmp=cmp_func)


                Example:



                >>> the_list = ['B', 'BB', 'AA', 'A', 'Z', 'C', 'D']
                >>> sorted(the_list, cmp=cmp_func)
                ['A', 'B', 'C', 'D', 'Z', 'AA', 'BB']


                Note, if your list is a mix of upper and lower case replace cmp(a, b) with cmp(a.lower(), b.lower()) as python sorts 'a' > 'Z'.



                In python3 you'd need to be sorting objects with __lt__ style comparison functions defined or functools.cmp_to_key() which does that for you.






                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  Although Jochen Ritzel said you don't need cmp, this is actually a great use case for it! Using cmp you can sort by length and then alphabetically at the same time in half the time sorting twice would take!



                  def cmp_func(a, b):
                  # sort by length and then alphabetically in lowercase
                  if len(a) == len(b):
                  return cmp(a, b)
                  return cmp(len(a), len(b))

                  sorted_the_way_you_want = sorted(the_list, cmp=cmp_func)


                  Example:



                  >>> the_list = ['B', 'BB', 'AA', 'A', 'Z', 'C', 'D']
                  >>> sorted(the_list, cmp=cmp_func)
                  ['A', 'B', 'C', 'D', 'Z', 'AA', 'BB']


                  Note, if your list is a mix of upper and lower case replace cmp(a, b) with cmp(a.lower(), b.lower()) as python sorts 'a' > 'Z'.



                  In python3 you'd need to be sorting objects with __lt__ style comparison functions defined or functools.cmp_to_key() which does that for you.






                  share|improve this answer












                  Although Jochen Ritzel said you don't need cmp, this is actually a great use case for it! Using cmp you can sort by length and then alphabetically at the same time in half the time sorting twice would take!



                  def cmp_func(a, b):
                  # sort by length and then alphabetically in lowercase
                  if len(a) == len(b):
                  return cmp(a, b)
                  return cmp(len(a), len(b))

                  sorted_the_way_you_want = sorted(the_list, cmp=cmp_func)


                  Example:



                  >>> the_list = ['B', 'BB', 'AA', 'A', 'Z', 'C', 'D']
                  >>> sorted(the_list, cmp=cmp_func)
                  ['A', 'B', 'C', 'D', 'Z', 'AA', 'BB']


                  Note, if your list is a mix of upper and lower case replace cmp(a, b) with cmp(a.lower(), b.lower()) as python sorts 'a' > 'Z'.



                  In python3 you'd need to be sorting objects with __lt__ style comparison functions defined or functools.cmp_to_key() which does that for you.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered May 23 at 1:10









                  theannouncer

                  538923




                  538923






























                      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.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • 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%2f4659524%2fhow-to-sort-by-length-of-string-followed-by-alphabetical-order%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

                      Bressuire

                      Vorschmack

                      Quarantine