How can I make Minecraft look into a USB for the .Minecraft file? I can do a bit of coding so just tell me if I have to make a program just tell me what I need to make it do.
I would not recommend storing it on a USB and playing the game from there. I would recommend transferring worlds when you need to switch computers (I'm sure you can write a script to transfer files from the USB onto the computer or the other way around). However, if you must, i would recommend looking in the Minecraft launcher settings. I am fairly certain you can change the source destination folder in there (along with allocated memory to the game and other semi-useful tweaks).
This guide may be helpful: https://www.pcsteps.com/1346-create-portable-minecraft-usb-stick/