change weight of fileds programmaticaly in drupal 7 I have a registration form with different attribute like

Captcha and security questions which are coming from different modules. 

I want to change the display order of form elements. 

and i am using this code in my custom module 

function tenantwallet_form_user_register_form_alter(&amp;$form, &amp;$form_state){
    $form['#pre_render'][] = 'tenantwallet_form_alter_weight';

}
function tenantwallet_form_alter_weight($elements){

    $elements['field_first_name']['#weight'] = -50;
        $elements['field_last_name']['#weight']= -49;
        $elements['field_company_name']['#weight']=-48;
        #field_company_number, field_secondary_number, field_mobile_or_landline,field_gst_number, field_share_my_info, field_company_logo,field_facebook_id, field_mobile_conformation_code,field_date_of_birth,, field_gender, field_id_proof,field_secondary_id_proof, field_mobile_number,field_promo_emails_notifications,field_sugar_id, captcha, 
        $elements['captcha']['captcha_widgets']['#weight']=-50;
        $elements['pass']['#weight']=-47;
        $elements['questions'][0]['question']['#weight']= 45; 

    return $elements; 
}         


But this is not working. Can anybody tell me how to solve this. 
Thanks
it seems there are different scope in your form . 
Like question and captcha are in different scope. Try to give weight for each scope too. 
Then it will work for you. Like 

 $elements['questions']['#weight']=50;