简体   繁体   English

如何从 python 列表列表中删除外部引号?

[英]How to remove outer quotes from python list of lists?

I am trying to remove the single quotes(or double quotes if single quote is part of data) from list items and assign to a new list.我正在尝试从列表项中删除单引号(如果单引号是数据的一部分,则为双引号)并分配给新列表。

I want to transform list0 and assign to list1 such that list1 contains:我想转换 list0 并分配给 list1 使得 list1 包含:

list1=[AC , AB']

I've tried strip and split but it doesn't work when there are single quotes inside double quotes as data.我尝试过剥离和拆分,但是当双引号内有单引号作为数据时它不起作用。

list0=['AC ', " AB'"]

What you're trying to achieve doesn't make any sense.你想要达到的目标没有任何意义。 The quotes are necessary to denote that something is a string.引号是表示某事物是字符串所必需的。 In the expected output, you'd have a variable name AC and something invalid, being AC' .在预期的 output 中,您将有一个变量名AC和一些无效的东西,即AC'

If what you want is to remove spaces from strings, that would make sense, but it's not what you're asking.如果您想要从字符串中删除空格,那将是有道理的,但这不是您要问的。

Hope this helps clarify things a little.希望这有助于澄清一些事情。

Also, for further questions: note that it may help to include why you want to achieve something (here, for example, the question as is makes not much sense, but maybe you're reaching out to a greater goal which does make sense but stays unknown to us) and add all you tried and all you understand, so the answers can be the most specific possible.另外,对于进一步的问题:请注意,包括您想要实现某事的原因可能会有所帮助(例如,在这里,问题本身没有多大意义,但也许您正在实现一个更大的目标,这确实是有道理的,但我们不知道)并添加您尝试过的所有内容和您理解的所有内容,因此答案可能是最具体的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM