我如何找到一个对象在列表中出现两次(Python)

时间:2017-10-30 22:30:26

标签: python list

我有一个基本程序,允许用户将项目输入列表。如何检查输入是否已被放置两次?

这就是我开始的

a=input("")
a=a.title()
abilities=append(a)

我没有进一步,因为我找不到解决方案

非常感谢你的帮助

2 个答案:

答案 0 :(得分:0)

检查项目是否在列表中,如下所示:

if a in abilities:
    print("already in list")
else:
    abilities.append(a)

另外,修正使用append。

答案 1 :(得分:0)

private static String hostName = "sql11.freesqldatabase.com";
private static String dbName = "xxxx";
private static String user = "xxxx";
private static String password = "xxxx";
private static String portNumber = "xxxx";
private Connection connect() {
    String url ="jdbc:mysql://"+hostName+":"+portNumber+"/"+dbName+"?user="+user+"&password="+password;
    Connection conn = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e1) {
            e1.printStackTrace();
        }
        try {
            conn = DriverManager.getConnection(url);
        } catch (SQLException e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }
    return conn;
}