嗨,我正在尝试转换以下字符串列表:
lists=['111,222','121,121']
进入整数列表,但不断出错,任何建议都会有所帮助。
我尝试过:
results=[int(i) for i in lists]
print(results)
但不断收到“以10为底的int()的无效文字:'111,222'”
答案 0 :(得分:4)
您需要删除逗号,例如:
lists=['111,222','121,121']
result = [int(s.replace(',', '')) for s in lists]
print(result)
输出
[111222, 121121]
答案 1 :(得分:3)
这应该有效
public static void updateMerchants()
{
System.out.println("---------- A");
lock.lock();
DatabaseReference database = FirebaseDatabase.getInstance().getReference("users").child("merchants");
database.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
System.out.println("---------- B");
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
if (snapshot.exists()) {
System.out.println("----------exists");
}
}
lock.unlock();
System.out.println("---------- C");
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
Log.d("onCancelled: ", databaseError.toString());
}
});
updateMerchantsUtil();
}
private static void updateMerchantsUtil()
{
lock.lock();
System.out.println("---------- D");
lock.unlock();
}