You can populate lookup fields using an object with an external id field populated like so:
Custom_Object__c o = new Custom_Object__c(Account__r=new Account(External_ID__c='123'));
insert o;
However, when I want to dynamically assign values using the .put
method instead of the property, I receive an error:
Custom_Object__c co = new Custom_Object__c();
SObject new_obj = co.newSObject();
new_obj.put('Account__r', new Account(External_ID__c='123'));
From the above code I receive Invalid field Account__r for Custom_Object__c