子集列表:仅查找Python中的完全匹配项

这是我的列表:

function copyToClipboard(element) {
  let currentColor = $("#valueInput").val();
  let currentStyle = $(element).text();

  let newStyle = currentStyle.replace('--placeholder',"#" + currentColor);

  let currenttextColor = $("#button_cont").val();
  let currenttextStyle = $(element).text();

  let newtextStyle = currenttextStyle.replace('--placeholdtext',"#" + currenttextColor);


  var $temp = $("<input>");
  $("body").append($temp);
  $temp.val(newStyle).select();
  document.execCommand("copy");
  $temp.remove();

  var $tempt = $("<input>");
  $("body").append($tempt);
  $tempt.val(newtextStyle).select();
  document.execCommand("copy");
  $tempt.remove();
}

我想使用此方法仅获取列表中的完全匹配项。重要提示:我也使用index尝试过,但这只给了我第一场比赛。我需要SUBSTRING的所有完全匹配项。

#button_cont {
  color: #333;
  font-size: 18px;
  text-decoration: none;
  background-color: --placeholder;
  padding: 10px;
  /* border: 1px solid #ffffff; */
  border-radius: 5px 5px 5px 5px;
  -moz-border-radius: 5px 5px 5px 5px;
  -webkit-border-radius: 5px 5px 5px 5px;
  display: inline-block;
  transition: all 0.4s ease 0s;
}

我该怎么做? :/

koto21cn 回答:子集列表:仅查找Python中的完全匹配项

我认为您可能正在寻找endswith运算符。

尝试使用 [x for x in smalllist if x.endswith("PRO7")]

,

您也可以使用

[element for element in smalllist if element.split('.')[1]=='PRO7']

那样,即使您使用的是'1245.UNPRO7'

本文链接:https://www.f2er.com/3101613.html

大家都在问