Skip to main content

web-content

 https://github.com/chavalibala6-source/web-content

Comments

Popular posts from this blog

comparision

Example Input file1.txt shard1 host1: 6379 host2: 6379 host3: 6379 shard2 host4: 6379 host5: 6379 host6: 6379 file2.txt shard1 host1: 6379 host2: 6379 host3: 6379 shard2 host4: 6379 host5: 9999 host6: 6379 Python script to compare def parse_file ( filename ): """Read shard -> hosts mapping from file.""" shards = {} with open (filename, "r" ) as f: for line in f: parts = line.strip().split() if not parts: continue shard = parts[ 0 ] hosts = parts[ 1 :] shards[shard] = set (hosts) # use set for easy comparison return shards def compare_shards ( file1, file2 ): shards1 = parse_file(file1) shards2 = parse_file(file2) all_shards = set (shards1.keys()) | set (shards2.keys()) for shard in sorted (all_shards): hosts1 = shards1.get(shard, set ()) hosts2 = shards2.get(shard, set ())...

python basics: effective python ref

pantry = [ ('avocados', 1.25), ('bananas', 2.5), ('cherries', 15), ] for i, (item, count) in enumerate(pantry): print('#%d: %-10s = %.2f' % (i, item, count)) What It Prints (Correctly) #0: avocados = 1.25 #1: bananas = 2.50 #2: cherries = 15.00 #%d → prints the index number (0, 1, 2). %-10s → left-aligns the string (item name) in a field 10 characters wide. Example: "bananas " (adds spaces to align neatly). %.2f → prints the number with 2 decimal places. So the = sign belongs in the format string itself: '%-10s = %.2f' ✅ If you run the exact code above, you will not see separate lines with just the numbers. Instead, you’ll see neatly aligned item + count pairs. 👉 Do you want me to also show you the f-string version (more modern & cleaner than % formatting)? yes Perfect 👍 f-strings make this much cleaner and easier to read. Here’s your same example rewritten with f-strings: pantry = [ ('av...