4

Having constructed the following list:

NO_VACANCIES = ['no vacancies', 
                'not hiring', 
                'no open positions',
                'all positions are currently filled'
                'no positions are available'
                "don't have any vacancies"
                "we don't have any jobs available"
                "we don't have any positions available"
                'no positions are currently available']

... PyCharm suggested that I convert it to a set, but gave no justification:

enter image description here

What might be the benefits of such a conversion?

Pyderman
  • 14,809
  • 13
  • 61
  • 106
  • 1
    Do you need this to be ordered? If not a `set` is a better choice. Its faster etc etc etc – Gábor Erdős Feb 03 '16 at 15:32
  • It doesn't need to be ordered, no. – Pyderman Feb 03 '16 at 15:35
  • Please show the exact message shown by PyCharm. – yole Feb 03 '16 at 15:36
  • 2
    It entirely depends on how you use your data structure and what operations you execute using this structure. Read [TimeComplexity](https://wiki.python.org/moin/TimeComplexity) for more information. – Vincent Savard Feb 03 '16 at 15:38
  • @VincentSavard Thanks. Its usage is described here: http://codereview.stackexchange.com/questions/118594/object-oriented-web-scraping-with-python – Pyderman Feb 03 '16 at 15:39
  • 2
    Check this answer here: http://stackoverflow.com/questions/2831212/python-sets-vs-lists – LoVo Feb 03 '16 at 15:40
  • 1
    Given your upper case assignment, I assume this is intended to be an immutable constant. Sets prevent you from accidentally changing the data. – Alexander Feb 03 '16 at 15:42
  • 1
    Happens to me regularly using pycharm and in many cases where I certainly do not want a set. You can disable `"Convert Collection to set"` if you want to remove the suggestions. A simple example of where it suggests a set and I definitely don't want one `lst = [1,2,3];from random import shuffle;shuffle(lst)` – Padraic Cunningham Feb 03 '16 at 15:51
  • 1
    If order is not important and you have only unique items in it, I don't see a reason *why not to use* a set. Otherwise I also suggest using the settings of PyCharm as @PadraicCunningham suggests. – rbaleksandar Feb 03 '16 at 16:58

1 Answers1

4

The menu you show is not a suggestion; it's a tool (known as "intention action"). It gives you possibility to change this list into a set if you decide that you need a set instead of a list. It does not tell you that this list should be a set, or that a set is somehow better in general.

yole
  • 92,896
  • 20
  • 260
  • 197