删除列表中字符串中的重复字符串(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
最满意答案
我不认为你可以在运行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
require
d module in cache during the lifetime of the application. However, you can do something likedelete 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 whenrequire('./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在 ...
-
无法使用node.js安装jquery - 无法加载Contextify(Unable to install jquery with node.js - Unable to load Contextify)[2023-11-17]
所以这似乎是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 ...