fork download
  1. # Simple text summarizer
  2. def summarize_text(text, max_sentences=3):
  3. # Split the text into sentences
  4. sentences = text.split('.')
  5.  
  6. # Sort the sentences by length (as a basic approach)
  7. sorted_sentences = sorted(sentences, key=len, reverse=True)
  8.  
  9. # Get the top 'max_sentences' longest sentences
  10. summary = '. '.join(sorted_sentences[:max_sentences])
  11.  
  12. return summary
  13.  
  14. # Simulating reading from file (since online compilers may not support file operations)
  15. text = """Python is a high-level programming language.
  16. It is widely used in web development, data science, and automation.
  17. With its simple syntax and powerful libraries, Python makes it easier for developers to write efficient code.
  18. The language supports multiple programming paradigms, including procedural, object-oriented, and functional programming.
  19. Python's popularity has grown immensely, making it a go-to choice for beginners and experts alike."""
  20.  
  21. # Call the summarize function
  22. summary = summarize_text(text)
  23.  
  24. # Print the summarized text
  25. print("Summarized Text:\n", summary)
  26.  
Success #stdin #stdout 0.01s 7124KB
stdin
Standard input is empty
stdout
('Summarized Text:\n', "\nThe language supports multiple programming paradigms, including procedural, object-oriented, and functional programming.  \nWith its simple syntax and powerful libraries, Python makes it easier for developers to write efficient code. \nPython's popularity has grown immensely, making it a go-to choice for beginners and experts alike")