首页 \ 问答 \ 删除列表中字符串中的重复字符串(Remove duplicated string(s) in strings in a list)

删除列表中字符串中的重复字符串(Remove duplicated string(s) in strings in a list)

需要删除一些重复。

一个列表包含元素,其中的字符串包含由“;”分隔的字符串。 每个字符串中的字符串都可以被复制。 如:

"15-105;ZH0311;TZZGJJ; ZH0311; ZH0311;DOC",

字符串中有3个“ZH0311”(出现次数不固定)。 我需要消除重复并改进字符串(字符串内部序列无关紧要):

"15-105;TZZGJJ; ZH0311;DOC",

我想用“;”分割字符串 并将它们连接在一起。 我怎么能为整个列表做同样的事情?

a_list = [

"15~105;~ PO185-400CT;NGG;DOC",
"15~105;-1;NGG;DOC",
"15~105; 15~105; NGG;-10;NGG;DOC",
"15~55;J205~J208;POI;DOC",
"15-105;15-105;ZH0305~;WER /;TZZGJJ;DOC",
"15-105;ZH0311;TZZGJJ; ZH0311; ZH0311;DOC",
"15-115;15-115; PL026~ PL028; Dry;PTT"]

请注意这些字符串包含非ASCII字符。

顺便问一下:它不同于列表中的字符串,但列表中的列表和每个嵌套列表中的元素是重复的?


a need to remove some duplicates.

A list contains elements, which are strings contains strings separated by “;”. The strings in each string could be duplicated. Such as:

"15-105;ZH0311;TZZGJJ; ZH0311; ZH0311;DOC",

There are 3 “ZH0311” in the string (the number of appearing is not fixed). I need to eliminate the duplicates and refine the string to (sequence of strings inside doesn't matter):

"15-105;TZZGJJ; ZH0311;DOC",

I am thinking to split the strings by ";" and link them together. How can I do the same for the whole list?

a_list = [

"15~105;~ PO185-400CT;NGG;DOC",
"15~105;-1;NGG;DOC",
"15~105; 15~105; NGG;-10;NGG;DOC",
"15~55;J205~J208;POI;DOC",
"15-105;15-105;ZH0305~;WER /;TZZGJJ;DOC",
"15-105;ZH0311;TZZGJJ; ZH0311; ZH0311;DOC",
"15-115;15-115; PL026~ PL028; Dry;PTT"]

please note the strings contains Non-ASCII characters.

By the way question: Is it a difference that it’s not strings in the list, but lists in the list and elements in each nested list are duplicated?


原文:https://stackoverflow.com/questions/27054358
更新时间:2023-11-05 11:11

最满意答案

我不认为你可以在运行node.js应用程序时进行热交换。

Node.js在应用程序的生命周期内将require d模块保留在缓存中。 但是,你可以做类似的事情

delete require.cache[require.resolve('./module.js')]

或者,如果您想重新加载所有模块,那么

for (var key in require.cache) {
    delete require.cache[key];
}

这将从require cache中删除缓存的密钥,并强制node.js在下次发生require('./module.js')时重新加载模块。


I don't think you can do hot swapping while running a node.js application.

Node.js keeps the required module in cache during the lifetime of the application. However, you can do something like

delete require.cache[require.resolve('./module.js')]

Or if you want to reload all the modules, then

for (var key in require.cache) {
    delete require.cache[key];
}

This will delete the cached key from require cache and force node.js to reload the module next time when require('./module.js') occurs.

相关问答

更多
  • 这就是我认为是这种情况的“最正确的”答案。 假设你有一个名为quadtree.js的脚本文件。 您应该构建一个具有这种目录结构的自定义node_module ... ./node_modules/quadtree/quadtree-lib/ ./node_modules/quadtree/quadtree-lib/quadtree.js ./node_modules/quadtree/quadtree-lib/README ./node_modules/quadtree/quadtree-lib/some- ...
  • > process.version 'v0.6.8' > process.versions { node: '0.6.8', v8: '3.6.6.19', ares: '1.7.5-DEV', uv: '0.6', openssl: '0.9.8g' } > process.version 'v0.6.8' > process.versions { node: '0.6.8', v8: '3.6.6.19', ares: '1.7.5-DEV', uv: '0.6', o ...
  • 如果没有看到你如何编译TypeScript,并且没有看到你如何尝试从节点中require()这些文件,那么很难回答这个问题。 即便如此,我可以告诉你,TypeScript和node.js都希望给require()一个相对于执行require的文件的路径。 如果我有一个看起来像这样的js / A.ts: import B = require("./B"); console.log(B.thing); 和js / B.ts看起来像这样: var myStuff = { thing: "I'm a th ...
  • 我不认为你可以在运行node.js应用程序时进行热交换。 Node.js在应用程序的生命周期内将require d模块保留在缓存中。 但是,你可以做类似的事情 delete require.cache[require.resolve('./module.js')] 或者,如果您想重新加载所有模块,那么 for (var key in require.cache) { delete require.cache[key]; } 这将从require cache中删除缓存的密钥,并强制node.js在 ...
  • 所以这似乎是32位与64位的问题,并且与此节点的node.js v0.6.11特别相关。 显然,Contextify是一个64位的库,但node.js 0.6.11的下载是32位可执行文件。 降级到v0.6.10似乎对我有用。 不确定这对未来意味着什么,但这里有我发现的任何其他感兴趣的资源: https://github.com/brianmcd/contextify/issues/19 http://www.websector.de/blog/2011/12/15/quick-tip-node-how-t ...
  • 经过一番挖掘后。 我发现我们可以调用已编译的模式 var ModelA = mongoose.model('collectionA'); 而在DBref中, ref:'ModelA'将会发挥魔力。 但是, var ModelA=require('./A.js'); 需要在调用mongoose.model之前调用,以便在该文件本身中编译模型。 After some more digging around. I figured out that we can call the already compiled ...
  • 听起来你正在创建某种插件系统。 我想看看Node VM: http : //nodejs.org/docs/latest/api/vm.html 它允许您在沙箱中加载和运行代码,这意味着当它完成所有内部分配时,应该再次释放它。 它被标记为不稳定,但这并不意味着它不起作用。 这意味着API可能会在未来的Node版本中发生变化。 例如,基于节点的smtp服务器Haraka使用VM模块(重新)加载插件。 It sounds like you're creating some sort of plugin syst ...
  • 如果驱动程序是node.js模块,您可以将它们放在npm存储库中并通过编程方式通过npm进行安装: var npm = require('npm'); function install (module, callback) { npm.load({ save : true, loglevel : 'silent' }, function (err) { if (err) return callback(err); npm.c ...
  • 备查: node.js的vm模块有几个runInContext()函数,它们将有效地沙盒化执行并阻止访问其范围之外的变量。 这里有一篇博客文章 ,讨论了不同版本之间的差异,并提供了基准测试 还有一个可用于node.js的沙箱模块 在沙盒中运行东西的缺点是执行速度慢得多 结论:在沙箱的范围内存储函数并安全地执行它们并非不可能,它不是很实用。 替代解决方案:如果功能本身不是太复杂,那么以DSL的形式存储呼叫并在之后解析它们并非不可能。 For future reference: node.js' vm modu ...
  • 函数require()通常用于在大多数应用程序运行之前缓存模块或配置文件。 您可以考虑使用require() ,如下所示: var file = fs.readFileSync('/path'); // depending on the file type eval(file); JSON.parse(file); 这样做的原因是依赖性按顺序加载。 如果要在初始化应用程序后读取文件,则应使用异步读取,并在回调中进行响应,如下所示: var http = require('http'); http.cre ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)