为什么PyCharm建议我将列表转换为集合?

时间:2016-02-03 15:31:23

标签: python list optimization set pycharm

构建了以下列表:

 class RecipesController < ApplicationController
  def index
    @search_term = params[:search] || "chocolate"
    @recipes_found = Recipe.for(@search_term)
  end
end

...... PyCharm建议我将其转换为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'] ,但没有说明理由:

enter image description here

这种转换有什么好处?

1 个答案:

答案 0 :(得分:3)

您显示的菜单不是建议;它是一种工具(称为“意图行动”)。如果您确定需要集合而不是列表,则可以将此列表更改为集合。它并没有告诉你这个列表应该是一个集合,或者一个集合在某种程度上更好。