Greetings,
I am new to Python and messing around with a script with that will read a text file. Each line in the text file contains a three digit number from 000 to 999, the number of lines in the text file can vary. The script I made counts the number of occurrences for each number. However what I want to expand that and get the numeric anagram count.
For example if I have the list as shown below:
123
132
750
213
231
312
321
123
990
570
i would like the output to be:
(123,132,213,231,321,312) = 7
(099,909,990) = 1
(057, 075, 507, 570, 705, 750) = 2
This is the code I have to count the occurrences of a number. I know it can be cleaned up a but I am still just learning and will figure out how to clean it up, but I just need help with the code for the numeric anagram portion. I have searched the forum but only came across word anagram code. Any help would be greatly appreciated.
Regards,
Monty
I am new to Python and messing around with a script with that will read a text file. Each line in the text file contains a three digit number from 000 to 999, the number of lines in the text file can vary. The script I made counts the number of occurrences for each number. However what I want to expand that and get the numeric anagram count.
For example if I have the list as shown below:
123
132
750
213
231
312
321
123
990
570
i would like the output to be:
(123,132,213,231,321,312) = 7
(099,909,990) = 1
(057, 075, 507, 570, 705, 750) = 2
This is the code I have to count the occurrences of a number. I know it can be cleaned up a but I am still just learning and will figure out how to clean it up, but I just need help with the code for the numeric anagram portion. I have searched the forum but only came across word anagram code. Any help would be greatly appreciated.
Regards,
Monty
1 2 3 4 5 6 7 8 9 10 11 12 |
for occurance in range ( 000 , 100 ): file = open ( "/home/monty/Documents/Python_Projects/Book1-new.txt" , "r" ) data = file .read() occurance_fill = f "{occurance:03d}" occurances = data.count( str (occurance_fill)) for occurance2 in range ( 100 , 1000 ): file = open ( "/home/monty/Documents/Python_Projects/Book1-new.txt" , "r" ) data = file .read() occurance2_fill = f "{occurance2}" occurances = data.count( str (occurance2_fill)) print ( str (occurance2_fill) + " : " + str (occurances)) |
Attached Files