简体   繁体   English

如何从集合中的字符串中删除多余的引号?

[英]How to remove extra quotes from strings in a set?

I am working on a method and trying to return a list in the format List[Tuple[Set[str], Set[str]]] but I can't figure out how to remove extra quotes.我正在研究一种方法并尝试以List[Tuple[Set[str], Set[str]]]格式返回一个列表,但我不知道如何删除额外的引号。 self._history[dates[dat]]._ridings is a list of strings. self._history[dates[dat]]._ridings 是一个字符串列表。 what this method does is check the voting areas in a election then comparing those areas with next election or previous election to see which areas were in first but not in second and which were in second but not in first and those are the two elements of tuple.这种方法的作用是检查选举中的投票区域,然后将这些区域与下一次选举或上一次选举进行比较,以查看哪些区域在第一但不在第二,哪些在第二但不在第一,这些是元组的两个元素. there could be more than one area which may or may not be present in this election.在这次选举中可能存在或不存在的区域可能不止一个。 self._history[dates[dat]]._ridings is a list with certain areas in a election and i add 1 to dat so it compares with the next election so every election is compared with the previous one. self._history[dates[dat]]._ridings 是一个包含选举中某些区域的列表,我在 dat 上加 1,这样它就会与下一次选举进行比较,这样每次选举都会与前一次进行比较。

I have tried using split and replace methods but doesn't seems to be working since it is a set not string我曾尝试使用 split 和 replace 方法,但似乎不起作用,因为它是一个集合而不是字符串

list1 = []
    dates = list(self._history)
    for dat in range(0, len(dates) - 1):
        a = set(self._history[dates[dat]]._ridings)
        b = set(self._history[dates[dat + 1]]._ridings)
        list1.append(tuple([(a-b), (b-a)]))
    return list1

Expected : [({"St. Paul's...St. Paul's"})]预期: [({"St. Paul's...St. Paul's"})]
Actual : [({'"St. Paul.... Paul\\'s"'})]实际 : [({'"St. Paul.... Paul\\'s"'})]

使用 substring 函数删除索引 0 处的字符和索引处的字符(字符串长度 - 1)

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

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