table for jyothi calcuation.
def process_lines_to_table(data, house_reserved):
"""Processes lines of data, extracting first and third words, and organizes them into a table."""
# Initialize the table with empty sets to hold multiple values
table = {
"a1": set(), "b1": set(), "c1": set(), "d1": set(),
"a2": set(), "b2": set(), "c2": set(), "d2": set(),
"a3": set(), "b3": set(), "c3": set(), "d3": set(),
"a4": set(), "b4": set(), "c4": set(), "d4": set(),
}
# Process each line and extract the first and third words
for line in data.strip().split('\n'):
words = line.split()
if len(words) >= 3: # Ensure there are at least 3 words
word1 = words[0] # First word (planet)
word3 = words[2] # Third word (house)
# Check if word3 matches any key in house_reserved
if word3 in house_reserved:
cell = house_reserved[word3] # Get corresponding cell
table[cell].add(word1) # Add word1 to the corresponding cell set
return table
def display_table(table):
"""Displays the content of the table in the specified format."""
for key in sorted(table.keys()): # Sort keys to maintain order
values = ', '.join(table[key]) if table[key] else ''
print(f"{key}={{ {values} }}", end=' ')
print() # For a new line after the table output
# Sample input data
sample_data = """
Lagna 00 Tula
Surya 00 Tula
Chandra 19 Kany
Mangal 27 Tula
Budha 26 Tula
Guru 11 Mesh
Shukra 28 Tula
Rahu 12 Kark
Ketu 13 Maka
"""
# House mapping
House_reserved = {
"Meen": "a1", "Mesh": "b1", "Vibh": "c1", "Mithu": "d1",
"Kumb": "a2", "Kark": "d2",
"Maka": "a3", "Simh": "d3",
"Dhan": "a4", "Vish": "b4", "Tula": "c4", "Kany": "d4",
}
# Process and display the data
table_content = process_lines_to_table(sample_data, House_reserved)
display_table(table_content)