我如何解除这些附加变量:
(function($) {
$.fn.idiciesOfClass = function(c) {
return this.map((i, e) => $(e).hasClass(c) ? i : -1).toArray().filter(x => x > -1);
}
})(jQuery);
console.log('Apple class indicies:', $('.section').idiciesOfClass('apple').join(', '));
这是一个刽子手程序的一部分(我知道这可能不是最有效的方法,但我是python的新手,想给自己一个挑战)
答案 0 :(得分:0)
使用python list GROUPID CATEGORY TEST_RESULTS
------- ------------ ------------
001 red13tall
001 blue16small
003 yellow3tall
003 green2giant
005 red16short
005 green12bald orange14tall
6 rows selected.
方法which pop()
,即。
removes and returns last object or obj from the list
为避免从空列表中弹出,请考虑先检查:
wh.pop()
此外,您可能希望“捕获”弹出的条目并避免将其打印到终端,如:
if wh: # Makes sure there is something to pop()
wh.pop()
答案 1 :(得分:0)
您可以通过多种方式从列表中删除项目,您可以按值或索引删除:
>>> foo = [1,2,3,4]
>>> foo.pop(1)
2
>>> foo
[1, 3, 4]
>>> foo.remove(1)
>>> foo
[3, 4]
>>> del foo[1]
>>> foo
[3]
>>>
尽管如此,我建议使用.pop()
。
编辑:根据您的评论,这是您想要做的吗?
>>> foo = ['h', 'm', 'f', 'd', 's']
>>> foo
['h', 'm', 'f', 'd', 's']
>>> ''.join(foo)
'hmfds'
>>>