首页 \ 问答 \ 在python中查找匹配的部分子字符串(Find matching partial substring in python)

在python中查找匹配的部分子字符串(Find matching partial substring in python)

我想检查名词中的任何元素是否与表中的任何一个元素匹配。

“设备”中的第一个元素。 显然它与“projname:dataset.devices”匹配。 如果找到匹配,循环应该中断,否则它应该检查名词中的第二个元素,即“今天”是否匹配表中的任何元素。

    tables = ["projname:dataset.devices","projname:dataset.attempts"]

    noun = [devices,today]

我用“名词在表格”中尝试了,我得到了空洞的结果。 我还可以尝试其他方法吗?

提前致谢 !!


I want to check if any element in noun matches any one of the elements in tables.

First element in nous in "devices". Clearly it matches with "projname:dataset.devices". If a match is found, loop should break, else it should check whether second element in noun, which is "today" matches any element in the tables.

    tables = ["projname:dataset.devices","projname:dataset.attempts"]

    noun = [devices,today]

I tried it with "noun in tables", i got empty result. Is there any other method that I can try with?

Thanks in advance !!


原文:https://stackoverflow.com/questions/41642549
更新时间:2023-04-15 17:04

最满意答案

您可以将它们包装在此:

<div style="white-space:nowrap;">

</div>

......以防止这种情况发生。

很难确切地知道问题的位置,你可以发布一些代码或制作一个JSFiddle吗?

更新:

我认为问题在于你使用基于百分比的宽度和px作为边距 - 很容易忘记你有多少可用空间,随后你的布局分崩离析。 考虑两个左侧浮动DIV,宽度为50%,边距为1px,每次都会突破两行,因为这超过了100%。

我改变了你的小提琴: http//jsfiddle.net/R62w4/5/

...只需将第一个DIV的左边距移动到另一个边缘的右边距到父容器,似乎为所有内容提供了足够的空间。

PS您可以使用基于百分比的边距,并确保您想要在一行上的所有内容<= 100%。


You might be able to wrap them in this:

<div style="white-space:nowrap;">

</div>

... to prevent that from happening.

It's hard to know exactly where the problem is, could you post some code or make a JSFiddle?

Update:

I believe the problem is that you are using % based widths and px for margins - it's easy to lose track of how much available space you have and subsequently your layout falls apart. Consider that two left floated DIVs of 50% width with 1px of margin each will break on to two lines every time because that's more than 100%.

I changed your fiddle a bit: http://jsfiddle.net/R62w4/5/

... just by moving the left margin from your first DIV and right margin from your other two to the parent container seems to give enough room for everything.

P.S. You can use % based margins and just make sure everything you want to be on one line stays <= 100%.

相关问答

更多
  • 你可以绑定到resize事件......重新resize你的元素大小: //bind event handler to the `resize` event $(window).on('resize', function () { //cache the window object for use in this function var $this = $(this); //set the height of my object to the height of the win ...
  • 将元素的绝对样式定位为相对于整个页面的大小。 因此,当页面变大时,div向左移动( left:560 )。 您可以使用位置相对: margin-top: -530px; position: relative; 要么 position: relative; top: -530px; 要么 margin-left: -120px;(because this div has a width of 240px) position: absolute; left: 50%; Position absolute ...
  • 您将不得不使用宽度百分比 - 即“相对”宽度。 编辑以反映变更的要求。 为什么不像这里一样用JS设置样式? 如何在JavaScript中设置div的宽度百分比? 或者,您可以将侦听器绑定到: http : //api.jquery.com/resize/ ,它检查页面的宽度,并调用该setSize函数 You'll have to use a width percentage - i.e. a "relative" width. Edited to reflect changed requirements. ...
  • 尝试这个 :
    img tag should be here
    和css img { max-width: 100%; float:left; } .div1{width:80%; float:left;} #textblock { display: inline; float:right; ...
  • DEMO 这可以通过去除固定的高度宽度来实现。 具有未指定宽度的元素设置为width:auto ,通常是元素内容的大小。 如果浮动元素无法相邻地放在页面上,它们将会换行。 CSS #menu{ border:1px; clear: both; /*height: 40px; Remove*/ /*width: 400px; Remove*/ float: left; position:relative; top:20px; background ...
  • 如何摆脱标签内的div标签。 因为您可以使用带标记的类。 请查看StackOverflow用户starx提供的以下示例 CSS a.divlink { display:block; width:500px; height:500px; float:left; } HTML
  • 在container div添加两个元素(左,右),并为此容器指定min-width