Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

New answers tagged

3

Before starting to talk about threads in Python, let's compare to a sequential implementation. I’ll start by building a test file using the following code: import string import random with open('test.txt', 'w') as f: for _ in range(20000000): line = ''.join(random.choice(string.printable) for _ in range(random.randint(0, 10000))) print(...


2

A more compact form would be - numbers = [input('Enter a number: ') for i in range(10)] odds = [x for x in numbers if x % 2 == 1] if odds: print max(odds) else: print 'No odd numbers input.' Explanation - numbers = [input('Enter a number: ') for i in range(10)] This line uses list comprehension to ask the user for 10 integers. These numbers will ...


Top 50 recent answers are included