使用下面的代码,我从“ for”循环中获得了单个词典(“ revised_user_dict”)。但是“ user_list”仅显示最后一个字典。像这样:
void sub (string str1, string str2){
int i,j,k;
for(i=0; i<=str2.size() ; i++){
for(j=0; j<=str1.size() ; j++ ){
if( str2[i] == str1[j] )
str1[j] = NULL;
}
}
cout<<str1;
[{A:B, C:D, E:F}, {A:B, C:D, E:F}, {A:B, C:D, E:F}, {A:B, C:D, E:F}, {A:B, C:D, E:F}...]
如何拥有
这样的列表user_list = []
revised_user_dict = {}
for user_dict in users_info:
first_name = user_dict["firstName"]
last_name = user_dict["lastName"]
email = user_dict["email"]
role = user_dict["role"]
revised_user_dict["first_name"] = first_name
revised_user_dict["last_name"]=last_name
revised_user_dict["email"] = email
revised_user_dict["role"] = role
user_list.append(revised_user_dict)
print(user_list)