0

I want to write a function in python that will take a list B and loop over another list A. if an item in list B is present in list A, it colours it red else ignores it and returns a list A with both coloured and uncoloured text. my code isn't working at the moment.

A = ["a", "b", "c", "c"]
B = ["a" "c"]

def color()
  for i in B:
    if i in A:
        print(Fore.RED + i) 

color()
Python learner
  • 1,159
  • 1
  • 8
  • 20

2 Answers2

0

You're looking for something like this?

A = ["a", "b", "c", "c"] 
B = ["a" "c"]
def color():
    for i in B: 
        if i in A: 
            A.append(Fore.Red+i)
    print(A)
color()
Python learner
  • 1,159
  • 1
  • 8
  • 20
0

I think you can use one loop for this.

class colors:
    RED = '\033[31m'
    ENDC = '\033[m'

A = ["a", "b", "c", "d"]
B = ["a", "c"]

def color():
    for i in A:
        if i in B:
            print(colors.RED + i + colors.ENDC + " ", end="")
        else:
            print(i + " ", end="")
color()
GAVD
  • 1,977
  • 3
  • 22
  • 40