Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何从元素中删除一个字符以及列表中另一个元素中的相应字符?_Python_List_Character_Del - Fatal编程技术网

Python 如何从元素中删除一个字符以及列表中另一个元素中的相应字符?

Python 如何从元素中删除一个字符以及列表中另一个元素中的相应字符?,python,list,character,del,Python,List,Character,Del,我需要将列表中的每个元素与其他元素进行比较。因此,比较sample[0]和sample[1],sample[0]和sample[2],sample[1]和sample[2] 如果比较中的任何一对具有$,则$,需要删除相应的元素 例如: Sample = ['A$$N','BBBC','$$AA'] 这可能不是最漂亮的代码,但可以完成这项工作 for i in range(len(sample1)): for j in range(i + 1, len(sample1)):

我需要将列表中的每个元素与其他元素进行比较。因此,比较
sample[0]
sample[1]
sample[0]
sample[2]
sample[1]
sample[2]

如果比较中的任何一对具有
$
,则
$
,需要删除相应的元素

例如:

Sample = ['A$$N','BBBC','$$AA']

这可能不是最漂亮的代码,但可以完成这项工作

for i in range(len(sample1)):
    for j in range(i + 1, len(sample1)):
        if i == "$" or j == "$":
            #Need to remove "$" and the corresponding element in the other list

   #Print the pairs

谢谢,它工作得很好。我更喜欢这样的代码而不是理解
for i in range(len(sample1)):
    for j in range(i + 1, len(sample1)):
        if i == "$" or j == "$":
            #Need to remove "$" and the corresponding element in the other list

   #Print the pairs
from itertools import combinations
sample = ['A$$N','BBBC','$$AA']
output = []
for i, j in combinations(range(len(sample)), 2):
    out = ['', '']
    for pair in zip(sample[i], sample[j]):
        if '$' not in pair:
            out[0] += pair[0]
            out[1] += pair[1]
    output.append(out)
print(output)