Python Forum
Numeric Anagrams - Count Occurances
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Numeric Anagrams - Count Occurances
#1
Question 
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

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

.txt   Book1-new.txt (Size: 4.69 KB / Downloads: 198)
Reply


Messages In This Thread
Numeric Anagrams - Count Occurances - by monty024 - Nov-12-2021, 01:30 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Numeric Enigma Machine idev 9 629 Mar-29-2024, 06:15 PM
Last Post: idev
  Row Count and coloumn count Yegor123 4 1,376 Oct-18-2022, 03:52 AM
Last Post: Yegor123
  How to get datetime from numeric format field klllmmm 3 2,023 Nov-06-2021, 03:26 PM
Last Post: snippsat
  Extract continuous numeric characters from a string in Python Robotguy 2 2,674 Jan-16-2021, 12:44 AM
Last Post: snippsat
  How to calculate column mean and row skip non numeric and na Mekala 5 5,002 May-06-2020, 10:52 AM
Last Post: anbu23
  Alpha numeric element list search rhubarbpieguy 1 1,811 Apr-01-2020, 12:41 PM
Last Post: pyzyx3qwerty
  convert a character to numeric and back Skaperen 2 2,134 Jan-28-2020, 09:32 PM
Last Post: Skaperen
  are numeric types passed by value or reference? rudihammad 4 2,659 Nov-19-2019, 06:25 AM
Last Post: rudihammad
  'Age' categorical (years -months -days ) to numeric Smiling29 4 2,967 Oct-17-2019, 05:26 PM
Last Post: Smiling29
  how to do a numeric sort Skaperen 11 5,011 Jul-12-2019, 09:50 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020