比较两个字符串以找到匹配的字符串

时间:2015-05-19 21:34:12

标签: python arrays python-2.7

我正在处理我的代码,因为我在sqlite3数据库中搜索匹配的字符串,与数组中的字符串列表进行比较。

我需要一些编写代码的帮助,因为在比较名为prog_id的数组中的字符串列表时,我不知道如何在数据库中找到匹配的字符串。

当我尝试这个时:

#get access to the database
profilePath = xbmc.translatePath(os.path.join('special://userdata/addon_data/script.tvguide', 'source.db'))
con = database.connect(profilePath)
cur = con.cursor()
cur.execute('SELECT button_ids, button_width FROM buttons')
buttonList = list()
buttons = cur.fetchall()

for pos_X, pos_Y, prog_id, prog_width in zip(positions_X, positions_Y, programs_id, program_width):
    if CurrentRow == 375:
        if int(CurrentWidth) > 342:
            if int(pos_X) == 375:
               for buttons_id in zip(buttonList):
                   if int(buttons_id) == int(prog_id):
                      print buttons_id
                      print button_width

以下是数组中buttons_id的字符串列表:

22:25:58 T:5624  NOTICE: ('3002',)
22:25:58 T:5624  NOTICE: ('3003',)
22:25:58 T:5624  NOTICE: ('3004',)
22:25:58 T:5624  NOTICE: ('3005',)
22:25:58 T:5624  NOTICE: ('3006',)
22:25:58 T:5624  NOTICE: ('3007',)
22:25:58 T:5624  NOTICE: ('3008',)
22:25:58 T:5624  NOTICE: ('3009',)
22:25:58 T:5624  NOTICE: ('3010',)
22:25:58 T:5624  NOTICE: ('3011',)
22:25:58 T:5624  NOTICE: ('3012',)
22:25:58 T:5624  NOTICE: ('3013',)
22:25:58 T:5624  NOTICE: ('3014',)
22:25:58 T:5624  NOTICE: ('3015',)
22:25:58 T:5624  NOTICE: ('3016',)
22:25:58 T:5624  NOTICE: ('3017',)
22:25:58 T:5624  NOTICE: ('3018',)
22:25:58 T:5624  NOTICE: ('3019',)
22:25:58 T:5624  NOTICE: ('3020',)
22:25:58 T:5624  NOTICE: ('3021',)
22:25:58 T:5624  NOTICE: ('3022',)
22:25:58 T:5624  NOTICE: ('3023',)
22:25:58 T:5624  NOTICE: ('3024',)
22:25:58 T:5624  NOTICE: ('3025',)
22:25:58 T:5624  NOTICE: ('3026',)
22:25:58 T:5624  NOTICE: ('3027',)
22:25:58 T:5624  NOTICE: ('3028',)
22:25:58 T:5624  NOTICE: ('3029',)
22:25:58 T:5624  NOTICE: ('3030',)
22:25:58 T:5624  NOTICE: ('3031',)
22:25:58 T:5624  NOTICE: ('3032',)
22:25:58 T:5624  NOTICE: ('3033',)
22:25:58 T:5624  NOTICE: ('3034',)
22:25:58 T:5624  NOTICE: ('3035',)
22:25:58 T:5624  NOTICE: ('3036',)
22:25:58 T:5624  NOTICE: ('3037',)
22:25:58 T:5624  NOTICE: ('3038',)
22:25:58 T:5624  NOTICE: ('3039',)
22:25:58 T:5624  NOTICE: ('3040',)
22:25:58 T:5624  NOTICE: ('3041',)
22:25:58 T:5624  NOTICE: ('3042',)
22:25:58 T:5624  NOTICE: ('3043',)
22:25:58 T:5624  NOTICE: ('3044',)
22:25:58 T:5624  NOTICE: ('3045',)
22:25:58 T:5624  NOTICE: ('3046',)
22:25:58 T:5624  NOTICE: ('3047',)
22:25:58 T:5624  NOTICE: ('3048',)
22:25:58 T:5624  NOTICE: ('3049',)
22:25:58 T:5624  NOTICE: ('3050',)
22:25:58 T:5624  NOTICE: ('3051',)
22:25:58 T:5624  NOTICE: ('3052',)
22:25:58 T:5624  NOTICE: ('3053',)
22:25:58 T:5624  NOTICE: ('3054',)
22:25:58 T:5624  NOTICE: ('3055',)
22:25:58 T:5624  NOTICE: ('3056',)
22:25:58 T:5624  NOTICE: ('3057',)
22:25:58 T:5624  NOTICE: ('3058',)
22:25:58 T:5624  NOTICE: ('3059',)
22:25:58 T:5624  NOTICE: ('3060',)
22:25:58 T:5624  NOTICE: ('3061',)
22:25:58 T:5624  NOTICE: ('3062',)
22:25:58 T:5624  NOTICE: ('3063',)
22:25:58 T:5624  NOTICE: ('3064',)
22:25:58 T:5624  NOTICE: ('3065',)
22:25:58 T:5624  NOTICE: ('3066',)
22:25:58 T:5624  NOTICE: ('3067',)
22:25:58 T:5624  NOTICE: ('3068',)
22:25:58 T:5624  NOTICE: ('3069',)
22:25:58 T:5624  NOTICE: ('3070',)
22:25:58 T:5624  NOTICE: ('3071',)
22:25:58 T:5624  NOTICE: ('3072',)
22:25:58 T:5624  NOTICE: ('3073',)
22:25:58 T:5624  NOTICE: ('3074',)
22:25:58 T:5624  NOTICE: ('3075',)
22:25:58 T:5624  NOTICE: ('3076',)
22:25:58 T:5624  NOTICE: ('3077',)
22:25:58 T:5624  NOTICE: ('3078',)
22:25:58 T:5624  NOTICE: ('3079',)
22:25:58 T:5624  NOTICE: ('3080',)
22:25:58 T:5624  NOTICE: ('3081',)
22:25:58 T:5624  NOTICE: ('3082',)
22:25:58 T:5624  NOTICE: ('3083',)
22:25:58 T:5624  NOTICE: ('3084',)
22:25:58 T:5624  NOTICE: ('3085',)
22:25:58 T:5624  NOTICE: ('3086',)
22:25:58 T:5624  NOTICE: ('3087',)
22:25:58 T:5624  NOTICE: ('3088',)
22:25:58 T:5624  NOTICE: ('3089',)
22:25:58 T:5624  NOTICE: ('3090',)
22:25:58 T:5624  NOTICE: ('3091',)
22:25:58 T:5624  NOTICE: ('3092',)
22:25:58 T:5624  NOTICE: ('3093',)
22:25:58 T:5624  NOTICE: ('3094',)
22:25:58 T:5624  NOTICE: ('3095',)
22:25:58 T:5624  NOTICE: ('3096',)
22:25:58 T:5624  NOTICE: ('3097',)
22:25:58 T:5624  NOTICE: ('3098',)
22:25:58 T:5624  NOTICE: ('3099',)
22:25:58 T:5624  NOTICE: ('3100',)
22:25:58 T:5624  NOTICE: ('3101',)
22:25:58 T:5624  NOTICE: ('3102',)
22:25:58 T:5624  NOTICE: ('3103',)
22:25:58 T:5624  NOTICE: ('3104',)
22:25:58 T:5624  NOTICE: ('3105',)
22:25:58 T:5624  NOTICE: ('3106',)
22:25:58 T:5624  NOTICE: ('3107',)
22:25:58 T:5624  NOTICE: ('3108',)
22:25:58 T:5624  NOTICE: ('3109',)
22:25:58 T:5624  NOTICE: ('3110',)
22:25:58 T:5624  NOTICE: ('3111',)
22:25:58 T:5624  NOTICE: ('3112',)
22:25:58 T:5624  NOTICE: ('3113',)
22:25:58 T:5624  NOTICE: ('3114',)
22:25:58 T:5624  NOTICE: ('3115',)
22:25:58 T:5624  NOTICE: ('3116',)
22:25:58 T:5624  NOTICE: ('3117',)
22:25:58 T:5624  NOTICE: ('3118',)
22:25:58 T:5624  NOTICE: ('3119',)
22:25:58 T:5624  NOTICE: ('3120',)
22:25:58 T:5624  NOTICE: ('3121',)
22:25:58 T:5624  NOTICE: ('3122',)
22:25:58 T:5624  NOTICE: ('3123',)
22:25:58 T:5624  NOTICE: ('3124',)
22:25:58 T:5624  NOTICE: ('3125',)
22:25:58 T:5624  NOTICE: ('3126',)
22:25:58 T:5624  NOTICE: ('3127',)
22:25:58 T:5624  NOTICE: ('3128',)
22:25:58 T:5624  NOTICE: ('3129',)
22:25:58 T:5624  NOTICE: ('3130',)
22:25:58 T:5624  NOTICE: ('3131',)
22:25:58 T:5624  NOTICE: ('3132',)
22:25:58 T:5624  NOTICE: ('3133',)
22:25:58 T:5624  NOTICE: ('3134',)
22:25:58 T:5624  NOTICE: ('3135',)
22:25:58 T:5624  NOTICE: ('3136',)
22:25:58 T:5624  NOTICE: ('3137',)
22:25:58 T:5624  NOTICE: ('3138',)
22:25:58 T:5624  NOTICE: ('3139',)
22:25:58 T:5624  NOTICE: ('3140',)
22:25:58 T:5624  NOTICE: ('3141',)
22:25:58 T:5624  NOTICE: ('3142',)
22:25:58 T:5624  NOTICE: ('3143',)
22:25:58 T:5624  NOTICE: ('3144',)
22:25:58 T:5624  NOTICE: ('3145',)
22:25:58 T:5624  NOTICE: ('3146',)
22:25:58 T:5624  NOTICE: ('3147',)
22:25:58 T:5624  NOTICE: ('3148',)
22:25:58 T:5624  NOTICE: ('3149',)
22:25:58 T:5624  NOTICE: ('3150',)
22:25:58 T:5624  NOTICE: ('3151',)
22:25:58 T:5624  NOTICE: ('3152',)
22:25:58 T:5624  NOTICE: ('3153',)
22:25:58 T:5624  NOTICE: ('3154',)
22:25:58 T:5624  NOTICE: ('3155',)
22:25:58 T:5624  NOTICE: ('3156',)
22:25:58 T:5624  NOTICE: ('3157',)
22:25:58 T:5624  NOTICE: ('3158',)
22:25:58 T:5624  NOTICE: ('3159',)
22:25:58 T:5624  NOTICE: ('3160',)
22:25:58 T:5624  NOTICE: ('3161',)
22:25:58 T:5624  NOTICE: ('3162',)
22:25:58 T:5624  NOTICE: ('3163',)
22:25:58 T:5624  NOTICE: ('3164',)
22:25:58 T:5624  NOTICE: ('3165',)
22:25:58 T:5624  NOTICE: ('3166',)
22:25:58 T:5624  NOTICE: ('3167',)
22:25:58 T:5624  NOTICE: ('3168',)
22:25:58 T:5624  NOTICE: ('3169',)
22:25:58 T:5624  NOTICE: ('3170',)
22:25:58 T:5624  NOTICE: ('3171',)
22:25:58 T:5624  NOTICE: ('3172',)
22:25:58 T:5624  NOTICE: ('3173',)
22:25:58 T:5624  NOTICE: ('3174',)
22:25:58 T:5624  NOTICE: ('3175',)
22:25:58 T:5624  NOTICE: ('3176',)
22:25:58 T:5624  NOTICE: ('3177',)
22:25:58 T:5624  NOTICE: ('3178',)
22:25:58 T:5624  NOTICE: ('3179',)
22:25:58 T:5624  NOTICE: ('3180',)
22:25:58 T:5624  NOTICE: ('3181',)
22:25:58 T:5624  NOTICE: ('3182',)
22:25:58 T:5624  NOTICE: ('3183',)
22:25:58 T:5624  NOTICE: ('3184',)
22:25:58 T:5624  NOTICE: ('3185',)
22:25:58 T:5624  NOTICE: ('3186',)
22:25:58 T:5624  NOTICE: ('3187',)
22:25:58 T:5624  NOTICE: ('3188',)
22:25:58 T:5624  NOTICE: ('3189',)
22:25:58 T:5624  NOTICE: ('3190',)
22:25:58 T:5624  NOTICE: ('3191',)
22:25:58 T:5624  NOTICE: ('3192',)
22:25:58 T:5624  NOTICE: ('3193',)
22:25:58 T:5624  NOTICE: ('3194',)
22:25:58 T:5624  NOTICE: ('3195',)
22:25:58 T:5624  NOTICE: ('3196',)
22:25:58 T:5624  NOTICE: ('3197',)
22:25:58 T:5624  NOTICE: ('3198',)
22:25:58 T:5624  NOTICE: ('3199',)
22:25:58 T:5624  NOTICE: ('3200',)
22:25:58 T:5624  NOTICE: ('3201',)
22:25:58 T:5624  NOTICE: ('3202',)
22:25:58 T:5624  NOTICE: ('3203',)
22:25:58 T:5624  NOTICE: ('3204',)
22:25:58 T:5624  NOTICE: ('3205',)
22:25:58 T:5624  NOTICE: ('3206',)
22:25:58 T:5624  NOTICE: ('3207',)
22:25:58 T:5624  NOTICE: ('3208',)
22:25:58 T:5624  NOTICE: ('3209',)
22:25:58 T:5624  NOTICE: ('3210',)
22:25:58 T:5624  NOTICE: ('3211',)
22:25:58 T:5624  NOTICE: ('3212',)
22:25:58 T:5624  NOTICE: ('3213',)
22:25:58 T:5624  NOTICE: ('3214',)
22:25:58 T:5624  NOTICE: ('3215',)
22:25:58 T:5624  NOTICE: ('3216',)
22:25:58 T:5624  NOTICE: ('3217',)
22:25:58 T:5624  NOTICE: ('3218',)
22:25:58 T:5624  NOTICE: ('3219',)
22:25:58 T:5624  NOTICE: ('3220',)
22:25:58 T:5624  NOTICE: ('3221',)
22:25:58 T:5624  NOTICE: ('3222',)
22:25:58 T:5624  NOTICE: ('3223',)
22:25:58 T:5624  NOTICE: ('3224',)
22:25:58 T:5624  NOTICE: ('3225',)
22:25:58 T:5624  NOTICE: ('3226',)
22:25:58 T:5624  NOTICE: ('3227',)
22:25:58 T:5624  NOTICE: ('3228',)
22:25:58 T:5624  NOTICE: ('3229',)
22:25:58 T:5624  NOTICE: ('3230',)
22:25:58 T:5624  NOTICE: ('3231',)
22:25:58 T:5624  NOTICE: ('3232',)
22:25:58 T:5624  NOTICE: ('3233',)
22:25:58 T:5624  NOTICE: ('3234',)
22:25:58 T:5624  NOTICE: ('3235',)
22:25:58 T:5624  NOTICE: ('3236',)
22:25:58 T:5624  NOTICE: ('3237',)
22:25:58 T:5624  NOTICE: ('3238',)
22:25:58 T:5624  NOTICE: ('3239',)
22:25:58 T:5624  NOTICE: ('3240',)
22:25:58 T:5624  NOTICE: ('3241',)
22:25:58 T:5624  NOTICE: ('3242',)
22:25:58 T:5624  NOTICE: ('3243',)
22:25:58 T:5624  NOTICE: ('3244',)
22:25:58 T:5624  NOTICE: ('3245',)
22:25:58 T:5624  NOTICE: ('3246',)
22:25:58 T:5624  NOTICE: ('3247',)
22:25:58 T:5624  NOTICE: ('3248',)
22:25:58 T:5624  NOTICE: ('3249',)
22:25:58 T:5624  NOTICE: ('3250',)
22:25:58 T:5624  NOTICE: ('3251',)
22:25:58 T:5624  NOTICE: ('3252',)
22:25:58 T:5624  NOTICE: ('3253',)
22:25:58 T:5624  NOTICE: ('3254',)
22:25:58 T:5624  NOTICE: ('3255',)
22:25:58 T:5624  NOTICE: ('3256',)
22:25:58 T:5624  NOTICE: ('3257',)
22:25:58 T:5624  NOTICE: ('3258',)
22:25:58 T:5624  NOTICE: ('3259',)
22:25:58 T:5624  NOTICE: ('3260',)
22:25:58 T:5624  NOTICE: ('3261',)
22:25:58 T:5624  NOTICE: ('3262',)
22:25:58 T:5624  NOTICE: ('3263',)
22:25:58 T:5624  NOTICE: ('3264',)
22:25:58 T:5624  NOTICE: ('3265',)
22:25:58 T:5624  NOTICE: ('3266',)
22:25:58 T:5624  NOTICE: ('3267',)
22:25:58 T:5624  NOTICE: ('3268',)
22:25:58 T:5624  NOTICE: ('3269',)
22:25:58 T:5624  NOTICE: ('3270',)
22:25:58 T:5624  NOTICE: ('3271',)
22:25:58 T:5624  NOTICE: ('3272',)
22:25:58 T:5624  NOTICE: ('3273',)
22:25:58 T:5624  NOTICE: ('3274',)
22:25:58 T:5624  NOTICE: ('3275',)
22:25:58 T:5624  NOTICE: ('3276',)
22:25:58 T:5624  NOTICE: ('3277',)
22:25:58 T:5624  NOTICE: ('3278',)
22:25:58 T:5624  NOTICE: ('3279',)
22:25:58 T:5624  NOTICE: ('3280',)
22:25:58 T:5624  NOTICE: ('3281',)
22:25:58 T:5624  NOTICE: ('3282',)
22:25:58 T:5624  NOTICE: ('3283',)
22:25:58 T:5624  NOTICE: ('3284',)
22:25:58 T:5624  NOTICE: ('3285',)
22:25:58 T:5624  NOTICE: ('3286',)
22:25:58 T:5624  NOTICE: ('3287',)
22:25:58 T:5624  NOTICE: ('3288',)
22:25:58 T:5624  NOTICE: ('3289',)
22:25:58 T:5624  NOTICE: ('3290',)
22:25:58 T:5624  NOTICE: ('3291',)
22:25:58 T:5624  NOTICE: ('3292',)
22:25:58 T:5624  NOTICE: ('3293',)
22:25:58 T:5624  NOTICE: ('3294',)
22:25:58 T:5624  NOTICE: ('3295',)
22:25:58 T:5624  NOTICE: ('3296',)
22:25:58 T:5624  NOTICE: ('3297',)
22:25:58 T:5624  NOTICE: ('3298',)
22:25:58 T:5624  NOTICE: ('3299',)
22:25:58 T:5624  NOTICE: ('3300',)
22:25:58 T:5624  NOTICE: ('3301',)
22:25:58 T:5624  NOTICE: ('3302',)
22:25:58 T:5624  NOTICE: ('3303',)
22:25:58 T:5624  NOTICE: ('3304',)
22:25:58 T:5624  NOTICE: ('3305',)
22:25:58 T:5624  NOTICE: ('3306',)
22:25:58 T:5624  NOTICE: ('3307',)
22:25:58 T:5624  NOTICE: ('3308',)
22:25:58 T:5624  NOTICE: ('3309',)
22:25:58 T:5624  NOTICE: ('3310',)
22:25:58 T:5624  NOTICE: ('3311',)
22:25:58 T:5624  NOTICE: ('3312',)
22:25:58 T:5624  NOTICE: ('3313',)
22:25:58 T:5624  NOTICE: ('3314',)
22:25:58 T:5624  NOTICE: ('3315',)
22:25:58 T:5624  NOTICE: ('3316',)
22:25:58 T:5624  NOTICE: ('3317',)
22:25:58 T:5624  NOTICE: ('3318',)
22:25:58 T:5624  NOTICE: ('3319',)
22:25:58 T:5624  NOTICE: ('3320',)
22:25:58 T:5624  NOTICE: ('3321',)
22:25:58 T:5624  NOTICE: ('3322',)
22:25:58 T:5624  NOTICE: ('3323',)
22:25:58 T:5624  NOTICE: ('3324',)
22:25:58 T:5624  NOTICE: ('3325',)
22:25:58 T:5624  NOTICE: ('3326',)
22:25:58 T:5624  NOTICE: ('3327',)
22:25:58 T:5624  NOTICE: ('3328',)
22:25:58 T:5624  NOTICE: ('3329',)
22:25:58 T:5624  NOTICE: ('3330',)
22:25:58 T:5624  NOTICE: ('3331',)
22:25:58 T:5624  NOTICE: ('3332',)
22:25:58 T:5624  NOTICE: ('3333',)
22:25:58 T:5624  NOTICE: ('3334',)
22:25:58 T:5624  NOTICE: ('3335',)
22:25:58 T:5624  NOTICE: ('3336',)
22:25:58 T:5624  NOTICE: ('3337',)
22:25:58 T:5624  NOTICE: ('3338',)
22:25:58 T:5624  NOTICE: ('3339',)
22:25:58 T:5624  NOTICE: ('3340',)
22:25:58 T:5624  NOTICE: ('3341',)
22:25:58 T:5624  NOTICE: ('3342',)
22:25:58 T:5624  NOTICE: ('3343',)
22:25:58 T:5624  NOTICE: ('3344',)
22:25:58 T:5624  NOTICE: ('3345',)
22:25:58 T:5624  NOTICE: ('3346',)
22:25:58 T:5624  NOTICE: ('3347',)
22:25:58 T:5624  NOTICE: ('3348',)
22:25:58 T:5624  NOTICE: ('3349',)
22:25:58 T:5624  NOTICE: ('3350',)
22:25:58 T:5624  NOTICE: ('3351',)
22:25:58 T:5624  NOTICE: ('3352',)
22:25:58 T:5624  NOTICE: ('3353',)
22:25:58 T:5624  NOTICE: ('3354',)
22:25:58 T:5624  NOTICE: ('3355',)
22:25:58 T:5624  NOTICE: ('3356',)
22:25:58 T:5624  NOTICE: ('3357',)
22:25:58 T:5624  NOTICE: ('3358',)
22:25:58 T:5624  NOTICE: ('3359',)
22:25:58 T:5624  NOTICE: ('3360',)
22:25:58 T:5624  NOTICE: ('3361',)
22:25:58 T:5624  NOTICE: ('3362',)
22:25:58 T:5624  NOTICE: ('3363',)
22:25:58 T:5624  NOTICE: ('3364',)
22:25:58 T:5624  NOTICE: ('3365',)
22:25:58 T:5624  NOTICE: ('3366',)
22:25:58 T:5624  NOTICE: ('3367',)
22:25:58 T:5624  NOTICE: ('3368',)
22:25:58 T:5624  NOTICE: ('3369',)
22:25:58 T:5624  NOTICE: ('3370',)
22:25:58 T:5624  NOTICE: ('3371',)
22:25:58 T:5624  NOTICE: ('3372',)
22:25:58 T:5624  NOTICE: ('3373',)
22:25:58 T:5624  NOTICE: ('3374',)
22:25:58 T:5624  NOTICE: ('3375',)
22:25:58 T:5624  NOTICE: ('3376',)
22:25:58 T:5624  NOTICE: ('3377',)
22:25:58 T:5624  NOTICE: ('3378',)
22:25:58 T:5624  NOTICE: ('3379',)
22:25:58 T:5624  NOTICE: ('3380',)
22:25:58 T:5624  NOTICE: ('3381',)
22:25:58 T:5624  NOTICE: ('3382',)
22:25:58 T:5624  NOTICE: ('3383',)
22:25:58 T:5624  NOTICE: ('3384',)
22:25:58 T:5624  NOTICE: ('3385',)
22:25:58 T:5624  NOTICE: ('3386',)
22:25:58 T:5624  NOTICE: ('3387',)
22:25:58 T:5624  NOTICE: ('3388',)
22:25:58 T:5624  NOTICE: ('3389',)
22:25:58 T:5624  NOTICE: ('3390',)
22:25:58 T:5624  NOTICE: ('3391',)
22:25:58 T:5624  NOTICE: ('3392',)
22:25:58 T:5624  NOTICE: ('3393',)
22:25:58 T:5624  NOTICE: ('3394',)
22:25:58 T:5624  NOTICE: ('3395',)
22:25:58 T:5624  NOTICE: ('3396',)
22:25:58 T:5624  NOTICE: ('3397',)
22:25:58 T:5624  NOTICE: ('3398',)
22:25:58 T:5624  NOTICE: ('3399',)
22:25:58 T:5624  NOTICE: ('3400',)
22:25:58 T:5624  NOTICE: ('3401',)
22:25:58 T:5624  NOTICE: ('3402',)
22:25:58 T:5624  NOTICE: ('3403',)
22:25:58 T:5624  NOTICE: ('3404',)
22:25:58 T:5624  NOTICE: ('3405',)
22:25:58 T:5624  NOTICE: ('3406',)
22:25:58 T:5624  NOTICE: ('3407',)
22:25:58 T:5624  NOTICE: ('3408',)
22:25:58 T:5624  NOTICE: ('3409',)
22:25:58 T:5624  NOTICE: ('3410',)
22:25:58 T:5624  NOTICE: ('3411',)
22:25:58 T:5624  NOTICE: ('3412',)
22:25:58 T:5624  NOTICE: ('3413',)
22:25:58 T:5624  NOTICE: ('3414',)
22:25:58 T:5624  NOTICE: ('3415',)
22:25:58 T:5624  NOTICE: ('3416',)
22:25:58 T:5624  NOTICE: ('3417',)
22:25:58 T:5624  NOTICE: ('3418',)
22:25:58 T:5624  NOTICE: ('3419',)
22:25:58 T:5624  NOTICE: ('3420',)
22:25:58 T:5624  NOTICE: ('3421',)
22:25:58 T:5624  NOTICE: ('3422',)
22:25:58 T:5624  NOTICE: ('3423',)
22:25:58 T:5624  NOTICE: ('3424',)
22:25:58 T:5624  NOTICE: ('3425',)
22:25:58 T:5624  NOTICE: ('3426',)
22:25:58 T:5624  NOTICE: ('3427',)
22:25:58 T:5624  NOTICE: ('3428',)
22:25:58 T:5624  NOTICE: ('3429',)
22:25:58 T:5624  NOTICE: ('3430',)
22:25:58 T:5624  NOTICE: ('3431',)
22:25:58 T:5624  NOTICE: ('3432',)
22:25:58 T:5624  NOTICE: ('3433',)
22:25:58 T:5624  NOTICE: ('3434',)
22:25:58 T:5624  NOTICE: ('3435',)
22:25:58 T:5624  NOTICE: ('3436',)
22:25:58 T:5624  NOTICE: ('3437',)
22:25:58 T:5624  NOTICE: ('3438',)
22:25:58 T:5624  NOTICE: ('3439',)
22:25:58 T:5624  NOTICE: ('3440',)
22:25:58 T:5624  NOTICE: ('3441',)
22:25:58 T:5624  NOTICE: ('3442',)
22:25:58 T:5624  NOTICE: ('3443',)
22:25:58 T:5624  NOTICE: ('3444',)
22:25:58 T:5624  NOTICE: ('3445',)
22:25:58 T:5624  NOTICE: ('3446',)
22:25:58 T:5624  NOTICE: ('3447',)
22:25:58 T:5624  NOTICE: ('3448',)
22:25:58 T:5624  NOTICE: ('3449',)
22:25:58 T:5624  NOTICE: ('3450',)
22:25:58 T:5624  NOTICE: ('3451',)
22:25:58 T:5624  NOTICE: ('3452',)
22:25:58 T:5624  NOTICE: ('3453',)
22:25:58 T:5624  NOTICE: ('3454',)
22:25:58 T:5624  NOTICE: ('3455',)
22:25:58 T:5624  NOTICE: ('3456',)
22:25:58 T:5624  NOTICE: ('3457',)
22:25:58 T:5624  NOTICE: ('3458',)
22:25:58 T:5624  NOTICE: ('3459',)
22:25:58 T:5624  NOTICE: ('3460',)
22:25:58 T:5624  NOTICE: ('3461',)
22:25:58 T:5624  NOTICE: ('3462',)
22:25:58 T:5624  NOTICE: ('3463',)
22:25:58 T:5624  NOTICE: ('3464',)
22:25:58 T:5624  NOTICE: ('3465',)
22:25:58 T:5624  NOTICE: ('3466',)
22:25:58 T:5624  NOTICE: ('3467',)
22:25:58 T:5624  NOTICE: ('3468',)
22:25:58 T:5624  NOTICE: ('3469',)
22:25:58 T:5624  NOTICE: ('3470',)
22:25:58 T:5624  NOTICE: ('3471',)
22:25:58 T:5624  NOTICE: ('3472',)
22:25:58 T:5624  NOTICE: ('3473',)
22:25:58 T:5624  NOTICE: ('3474',)
22:25:58 T:5624  NOTICE: ('3475',)
22:25:58 T:5624  NOTICE: ('3476',)
22:25:58 T:5624  NOTICE: ('3477',)
22:25:58 T:5624  NOTICE: ('3478',)
22:25:58 T:5624  NOTICE: ('3479',)
22:25:58 T:5624  NOTICE: ('3480',)
22:25:58 T:5624  NOTICE: ('3481',)
22:25:58 T:5624  NOTICE: ('3482',)
22:25:58 T:5624  NOTICE: ('3483',)
22:25:58 T:5624  NOTICE: ('3484',)

以下是prog_id数组中的字符串列表:

22:29:34 T:488  NOTICE: 3140
22:29:34 T:488  NOTICE: 3209
22:29:34 T:488  NOTICE: 3278
22:29:34 T:488  NOTICE: 3347
22:29:34 T:488  NOTICE: 3416

在我编写的代码中,我试图比较prog_id数组中的字符串,看看它是否可以在数据库中找到匹配的字符串buttons_id

你能否告诉我一个例子,当我与prog_idbuttons_id进行比较时,我如何在数组中找到匹配的字符串,看看我是否可以找到匹配的字符串来获取匹配的程序ID ?

1 个答案:

答案 0 :(得分:1)

如果要对button_id行进行分组,请使用prog行作为键,并检查翻译后的行是否在dict中,如果是这样,请将其附加到列表中:

d = {k:[] for k in prog}

for line in button_ids:
    trans = line.translate(None,"',()")
    if trans in d:
         d[trans].append(line)

或者使prog_id成为一个集合并检查已翻译的行是否在集合中:

d = set(prog_id)

for line in button_ids:
    if line.translate(None,"',()"):
        print(line)

str.translating后,你的行将与prog_id行格式相同:

button_ids = ["22:25:58 T:5624  NOTICE: ('3002',)", "22:25:58 T:5624  NOTICE: ('3003',)", "22:25:58 T:5624  NOTICE: ('3004',)", "22:25:58 T:5624  NOTICE: ('3005',)", "22:25:58 T:5624  NOTICE: ('3006',)", "22:25:58 T:5624  NOTICE: ('3007',)", "22:25:58 T:5624  NOTICE: ('3008',)", "22:25:58 T:5624  NOTICE: ('3009',)", "22:25:58 T:5624  NOTICE: ('3010',)", "22:25:58 T:5624  NOTICE: ('3484',)"]


for line in button_ids:
    print line.translate(None,"',()")

22:25:58 T:5624  NOTICE: 3002
22:25:58 T:5624  NOTICE: 3003
22:25:58 T:5624  NOTICE: 3004
22:25:58 T:5624  NOTICE: 3005
22:25:58 T:5624  NOTICE: 3006
22:25:58 T:5624  NOTICE: 3007
22:25:58 T:5624  NOTICE: 3008
22:25:58 T:5624  NOTICE: 3009
22:25:58 T:5624  NOTICE: 3010
22:25:58 T:5624  NOTICE: 3484

所以你可以比较,这比使用你的嵌套for循环更有效。

如果你想要一份所有比赛的清单:

st = set(prod_id)
matched = [line for line in button_ids if line.translate(None,"',()") in st]

如果你只是在最后一个值上匹配元组中的数字,你可以将数字提取到一个集合中:

st = {line.rsplit(None,1)[1] for line in prog_id}
matched = [line for line in button_ids if line.rsplit(None,1)[1].translate(None,"',()") in st]

print(matched)

在您提供的输入中输出以下内容:

["22:25:58 T:5624  NOTICE: ('3140',)", "22:25:58 T:5624  NOTICE: ('3209',)", "22:25:58 T:5624  NOTICE: ('3278',)", "22:25:58 T:5624  NOTICE: ('3347',)", "22:25:58 T:5624  NOTICE: ('3416',)"