根据Mahtematica中内部列表元素的字母顺序对列表进行排序(Sort a list of lists based on alphabetical order of inner list elements in Mahtematica)
我有一个内部列表可能长度不同的列表。 我需要根据内部列表元素的字母顺序对外部列表进行排序。 例如,给出一个列表
{{0, 0, 7}, {5, 0, 2, 3}, {0, 0, 10, 0}, {0, 6, 2}, {5, 1, 2}, {0, 3, 6, 1, 4}}
我想
Sort
后的输出
{{0, 0, 10, 0}, {0, 0, 7}, {0, 3, 6, 1, 4}, {0, 6, 2}, {5, 0, 2, 3}, {5, 1, 2}}
我只是不知道如何处理可变长度的内部列表以编写比较函数。 请帮忙。
编辑
顺便说一句,原来的清单是一个数字。
编辑2
例如,我有一个列表:
{{0,0,7},{5,0,2,3},{0,0,11,0},{0,0,1,12},{0,6,2},{ 1,2},{0,3,6,1,4}}
输出应该是:
{{0,0,1,12},{0,0,11,0},{0,0,7},{0,3,6,1,4},{0,6,2},{ 5,0,2,3},{5,1,2}}
原因是
1
在词汇上小于11
,小于7
。I have a list of lists with inner lists possibly of variable lengths. I need to sort the outer list based on the alphabetical order of the inner list elements. For example, given a list of
{{0, 0, 7}, {5, 0, 2, 3}, {0, 0, 10, 0}, {0, 6, 2}, {5, 1, 2}, {0, 3, 6, 1, 4}}
I want the output after
Sort
to be
{{0, 0, 10, 0}, {0, 0, 7}, {0, 3, 6, 1, 4}, {0, 6, 2}, {5, 0, 2, 3}, {5, 1, 2}}
I just do not know how to handle the variable lengths of inner lists in order to write a comparison function. Please help.
Edit
BTW, the original list is a numerical one.
Edit 2
For example, I have a list:
{{0, 0, 7}, {5, 0, 2, 3}, {0, 0, 11, 0}, {0, 0, 1, 12}, {0, 6, 2}, {5, 1, 2}, {0, 3, 6, 1, 4}}
The output should be:
{{0, 0, 1, 12}, {0, 0, 11, 0}, {0, 0, 7}, {0, 3, 6, 1, 4}, {0, 6, 2}, {5, 0, 2, 3}, {5, 1, 2}}
The reason is that
1
is lexically less than11
, which is less than7
.
原文:https://stackoverflow.com/questions/8595534
最满意答案
你不能,保证金不是元素的一部分。 但是你可以使用2个嵌套的DIV。 然后检测鼠标是否在外部DIV上方但不在内部DIV上方。 我确定媒体编辑器是这样做的(尽管我无法检查)。
例如使用jQuery检查:
$('#outer').is(":hover") && !$('#inner').is(":hover")
更新:在Medium的示例图像中,外部DIV将是
#editor_4
而不是内部DIV,还有其他元素,但原则是(或可能)相同。对于许多行,在每个行的鼠标悬停事件中设置/清除boolen标志可能更有效,而不是每次都选择和测试每个元素。
Update2:我创建了一个使用单个布尔标志实现此功能的jsFiddle 。
You can't, the margin isn't part of the element. But you can use 2 nested DIVs. Then detect whether the mouse is over the outer DIV but not over the inner DIV. I'm sure that's how the Medium editor does it (although I can't check).
e.g. check using jQuery:
$('#outer').is(":hover") && !$('#inner').is(":hover")
Update: In the example image from Medium, the outer DIV would be
#editor_4
and instead of the inner DIV, there are other elements, but the principle is (or could be) the same.With many lines, it may be more efficient to set/clear boolen flags in mouseover events for each of the lines instead of selecting and testing each element every time.
Update2: I created a jsFiddle that implements this using a single boolean flag.
相关问答
更多-
负边际在css中是有效的,并且理解(兼容)行为主要是基于框模型和边缘折叠。 虽然某些情况更复杂,但在研究规范后可以避免很多常见的错误。 例如,您的示例代码的渲染由css规范指导,如计算绝对定位的未替换元素的高度和边距所述。 如果我做一个图形表示,我可能会去这样的东西(不按比例): 8px在顶部丢失了8px ,但这并不影响内容和填充框 。 因为你的元素是绝对定位的,所以向上移动元素8px不会对布局造成任何进一步的干扰; 静态流量内容并不总是如此。 奖金: 仍然需要说服阅读规格是要走的路(相对于这样的文章 )? ...
-
你根本不需要JS。 它可以通过CSS使用:hover来实现 .parent { position: relative; margin-left: 40%; background: green; } .parent:hover .image2{ visibility: visible } .image1 { position: absolute; top: 0; left: 0; } .image2 { position: absolut ...
-
你不能,保证金不是元素的一部分。 但是你可以使用2个嵌套的DIV。 然后检测鼠标是否在外部DIV上方但不在内部DIV上方。 我确定媒体编辑器是这样做的(尽管我无法检查)。 例如使用jQuery检查: $('#outer').is(":hover") && !$('#inner').is(":hover") 更新:在Medium的示例图像中,外部DIV将是#editor_4而不是内部DIV,还有其他元素,但原则是(或可能)相同。 对于许多行,在每个行的鼠标悬停事件中设置/清除boolen标志可能更有效,而不 ...
-
hover = ActionChains(self.driver).move_by_offset(1,1) hover.click(self.driver.find_element_by_css_selector('[data-aid="sb-toggle"]')).perform() 偏移量(1,1)如果我把鼠标悬停在页面的左上角,然后点击按钮。 hover = ActionChains(self.driver).move_by_offset(1,1) hover.click(self. ...
-
鼠标悬停在父div上的子元素的nth-child?(Target nth-child of the child element on mouseover the parent div?)[2023-11-19]
事实证明,它看起来你试图根据h3是存在于第一个容器内还是第二个或第三个(而不是h3元素的子索引)来设置left位置。 因此,应该将nth-child伪类选择器应用于容器。 所以,你的选择器需要如下所示: div > div:nth-child([n]):hover .customoverlay .inneroverlaybox h3 将:nth-child选择器应用于h3或div.inneroverlaybox或a.customoverlay将不会给出预期的输出,因为它们都是其父级的第一个(也是唯一的子级 ... -
不知道你知道多少,所以从一开始就要开始 - 你需要把它放在网页(例如html)或javascript文件中。 在网页内,您将需要一个脚本部分: 在脚本中你需要在jquery中指定方法(我更喜欢mouseenter,见这里 )。 像(从你的jsfiddle更新): $(document).ready(function () { var bouncetime = 1700; var ballheight ...
-
秒触发器有效