I have a list of file names and I need to be able to count how many of the same file gets repeated for each file name [closed]

If you already have a list of filenames use collections.Counter: from collections import Counter files = [“foo.txt”,”foo.txt”,”foobar.c”] c = Counter(files) print (c) Counter({‘foo.txt’: 2, ‘foobar.c’: 1}) The keys will be your files and the values will be how many times the file appears in your list:

How to create a counter for each new instance of string in python?

File input.txt ##### pears oranges ##### apples grapes ##### grapes oranges ##### apples pears oranges grapes File run.py lines = [l.strip() for l in open(‘input.txt’, ‘r’).readlines()] hash_count = 0 for line in lines: if line == ‘#####’: hash_count += 1 print(line) else: print(line + ‘_’ + str(hash_count)) Run it: $ python run.py Output: ##### pears_1 … Read more

How to limit items from for loop?

Dont know what you mean there. But here is what I understand from your question <?php for ($i=0; $i< count($contentdinamit[“chart”][“songs”][“song”]); $i++ ) { if(($i+1)<=10){//limit your item by 10 echo'<li class=”up”><a href=”‘ .$contentdinamit[“chart”][“songs”][“song”][“$i”][“artist_name”].'”><strong>’ .$contentdinamit[“chart”][“songs”][“song”][“$i”][“song_name”].'</strong></a><br /><a href=”‘ .$contentdinamit[“chart”][“songs”][“song”][“$i”][“artist_name”].'”>’ .$contentdinamit[“chart”][“songs”][“song”][“$i”][“artist_name”].'</a></li>’; } } ?>