1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Python list of tuples while iterating unable to see an element but when printing it...

Discussão em 'Python' iniciado por Stack, Novembro 26, 2025.

  1. Stack

    Stack Membro Participativo

    I am using regular expression to get the filenames and count from a SAS log using Python. Pattern I am using

    pattern = re.compile(r'filename="([^"]+_\d{8})".*?Note:\s+There were (\d+)', re.DOTALL)


    I am getting the list of tuples with filenames and count. This is working fine. But when I am trying to get the filenames seperately based on below code -

    data = []
    [data.append({'filename':filename, 'count':count }) for filename, count in file_and_cnt]


    One of the element is skipping. When I do this

    for elm in file_and_cnt:
    print(elm[0])


    The filename is still skipping. But when I do the below -

    for elm in file_and_cnt:
    if 'target' in elm[0]:
    print(elm[0])


    I am getting all the element, earlier the element which was missing was 'target' file only and I can see the missing element. I tried to strip, remove bad characters, changed the encoding while doing finall, finditer and all it did not worked.

    Can you please help?

    Continue reading...

Compartilhe esta Página