Search This Blog

Monday, 31 July 2023

Python Tips and tricks

 num1 = 1_000_000_000

num2 = 2_000
ans = num1*num2
print(f'{ans:_}')
print(f'{ans:,}')

2_000_000_000_000 2,000,000,000,000

# Get frequently occurring item from the list
x = [1,2,1,3,4,1,2,4,1]
most = max(set(x), key=x.count)
print(most)
1

# Tuples insert a item into a tuple list

myTuple = ([1,2],[3])
myTuple[1].append(4)
print(myTuple)
([1, 2], [3, 4])

# Clean python input Handling

def do_this():
    print('Doing this')

def do_that():
    print('Doing that')

match input('Do this or that? '):
    case 'this':
        do_this()
    case 'that':
        do_this()
    case _:
        print('Invalid Input!')



Ansible_Notes

   ansible -i inventory.ini -m ping all   # inventory.ini it will ping to the hosts which are in inventory # ansible -i inventory.ini -m pin...