I need to remove the numbers (str) in a list I made for a project, and if is possible I want to save them in a variable. I'm a beginner at python, so I dont know how to do it. ¿Can anyone help me?
names = ['MATEO', '3869', 'AGUSTIN', '2641', 'BENJAMIN', '2337', 'TOMAS', '2235', 'LUCAS', '2146', 'SANTIAGO', '2124', 'GASPAR', '1922', 'JOAQUIN', '1750', 'VICENTE', '1717', 'MATIAS', '1712', 'MAXIMILIANO', '1704', 'MARTIN', '1587', 'ALONSO', '1573', 'FACUNDO', '1439', 'LUCIANO', '1402', 'EMILIANO', '1296', 'JOSE', '1287', 'CRISTOBAL', '1267', 'MAXIMO', '1248', 'BRUNO', '1227', 'JULIAN', '1126', 'LIAM', '1088', 'DANTE', '1083', 'GABRIEL', '1082', 'DIEGO', '1052', 'NICOLAS', '1021', 'SANTINO', '950', 'LEON', '946', 'SIMON', '940', 'JUAN', '901', 'SEBASTIAN', '855', 'RENATO', '717', 'IAN', '701', 'THOMAS', '684', 'GAEL', '673', 'AMARO', '670', 'RAFAEL', '656', 'DANIEL', '652', 'PEDRO', '652', 'IGNACIO', '640', 'FELIPE', '638', 'SAMUEL', '578', 'ANGEL', '565', 'BASTIAN', '564', 'FRANCO', '560', 'VALENTIN', '546', 'THIAGO', '530', 'MARIANO', '525', 'LUIS', '502', 'CLEMENTE', '482', 'FRANCISCO', '479', 'DAVID', '464', 'MATTEO', '464', 'JAVIER', '462', 'ISAAC', '444', 'EMILIO', '435', 'PABLO', '434', 'DYLAN', '432', 'DAMIAN', '425', 'CARLOS', '415', 'ALEXANDER', '415', 'NOAH', '411', 'SALVADOR', '409', 'BALTAZAR', '401', 'FERNANDO', '401', 'MATHEO', '381', 'ELIAN', '372', 'AARON', '348', 'LEONARDO', '337', 'GUSTAVO', '335', 'ESTEBAN', '330', 'ELIAS', '328', 'BORJA', '322', 'MANUEL', '307', 'JORGE', '302', 'VALENTINO', '301', 'CRISTIAN', '299', 'ANDRES', '297', 'OLIVER', '296', 'MIGUEL', '277', 'VICTOR', '274', 'ALEJANDRO', '269', 'ETHAN', '238', 'RODRIGO', '238', 'EDUARDO', '231', 'LAUTARO', '231', 'CAMILO', '229', 'JOSUE', '228', 'MATHIAS', '227', 'ALAN', '217', 'FABIAN', '217', 'RAIMUNDO', '216', 'JESÚS', '205', 'EITHAN', '198', 'ALVARO', '194', 'LEANDRO', '183', 'IKER', '177', 'CHRISTOPHER', '174', 'EZEQUIEL', '173', 'ISAIAS', '173', 'MILAN', '173', 'LIAN', '172', 'LUKAS', '170', 'ISMAEL', '169', 'RICARDO', '168', 'CRISTOPHER', '167', 'HECTOR', '162', 'ABRAHAM', '162', 'GUILLERMO', '157', 'LORENZO', '153', 'PASCUAL', '151', 'JEAN', '150', 'AXEL', '148', 'EMMANUEL', '148', 'SERGIO', '148', 'DEMIAN', '147', 'ALFONSO', '142', 'ANTONIO', '140', 'ALEX', '139', 'OSCAR', '138', 'JEREMIAS', '132', 'GONZALO', '128', 'ANTHONY', '127', 'MOISÉS', '126', 'JONATHAN', '125', 'DOMINGO', '124', 'ARTURO', '122', 'NAHUEL', '121', 'MAURICIO', '120', 'MARIO', '119', 'ERICK', '119', 'THEO', '118', 'MARCELO', '116', 'AMARU', '114', 'AUGUSTO', '114', 'PIERO', '114', 'ADRIAN', '114', 'LYAN', '112', 'ABDIEL', '110', 'AUSTIN', '109', 'CÉSAR', '109', 'ROMAN', '109', 'IVAN', '108', 'ENZO', '107', 'KEVIN', '104', 'CLAUDIO', '99', 'EMANUEL', '99', 'MAX', '98', 'CHRISTIAN', '98', 'ALEXIS', '95', 'GASTÓN', '94', 'DEREK', '93', 'FEDERICO', '92', 'MARCO', '91', 'EYDAN', '89', 'ANIBAL', '87', 'PATRICIO', '86', 'RAÚL', '82', 'OCTAVIO', '78', 'JACOB', '78', 'FÉLIX', '78', 'DARÍO', '78', 'LYAM', '77', 'ROBERTO', '75', 'ARIEL', '74', 'ZAID', '72', 'WILLIAM', '72', 'EMIR', '71', 'ISRAEL', '71', 'STEFANO', '71', 'DILAN', '70', 'JAIME', '70', 'BAUTISTA', '70', 'WILLIAMS', '69', 'SANTI', '68', 'EVAN', '68', 'ADRIEL', '68', 'BALTASAR', '66', 'CRISTOFER', '66', 'JHON', '65', 'ELUNEY', '64', 'HUGO', '63', 'CALEB', '63', 'JOSEPH', '63', 'PAOLO', '63', 'KYLIAN', '63', 'SAMIR', '62', 'TAHIEL', '62', 'NEHEMIAS', '62', 'JEREMY', '61', 'JOSIAS', '60', 'LEONEL', '59', 'ANDER', '59', 'IÑAKI', '59', 'OMAR', '59', 'ANGELO', '57', 'ALESSANDRO', '57', 'JOEL', '57', 'BELTRÁN', '56', 'NATHAN', '56', 'JOHN', '56', 'JOSHUA', '56', 'MILOVAN', '55', 'EFRAÍN', '55', 'JORDAN', '55', 'EDWARD', '54', 'HANS', '54', 'GIOVANNI', '53', 'ANTU', '53', 'ARON', '53', 'JARED', '53', 'LOGAN', '52', 'JOHAN', '51', 'MARCOS', '51', 'TOBIAS', '51', 'LEONIDAS', '51', 'EVANS', '50', 'MISAEL', '50', 'JULIO', '49', 'PAULO', '48', 'RODOLFO', '48', 'EDGAR', '48', 'ADOLFO', '46', 'MAURO', '46', 'RUBEN', '46', 'ABEL', '45', 'IZAN', '45', 'ENRIQUE', '44', 'RICHARD', '44', 'ALBERTO', '44', 'NICANOR', '43', 'TEO', '43', 'DANILO', '43', 'ELIEL', '42', 'LUCA', '42', 'EXEQUIEL', '42', 'EIDAN', '42', 'SAID', '41', 'DORIAN', '41', 'LUAN', '41', 'MIKE', '40', 'DERECK', '40', 'INTI', '40', 'SAÚL', '40', 'ALONZO', '39', 'MICHAEL', '39', 'GERARDO', '38', 'LUCCA', '37', 'HERNÁN', '37', 'ANDERSON', '37', 'YAHIR', '37', 'FABIO', '36', 'AMIR', '36', 'ISAI', '35', 'JAYDEN', '35', 'EINAR', '35', 'NELSON', '35', 'ANTUAN', '35', 'GERMÁN', '34', 'LIONEL', '33', 'ANDRE', '33', 'AUKAN', '33', 'BRAYAN', '32', 'BRANDON', '32', 'PATRICK', '32', 'SILVESTRE', '31', 'TADEO', '31', 'ALEN', '31', 'STEVEN', '31', 'PAUL', '30', 'DOMINIC', '30', 'NATANAEL', '30', 'LUKA', '30', 'ADRIANO', '30', 'RAMIRO', '30', 'JAMES', '30', 'MATTHEW', '30', 'DEMIR', '30', 'MARVENS', '29', 'DARIEL', '29', 'ALFREDO', '29', 'GADIEL', '29', 'LUCCIANO', '29', 'ULISES', '28', 'JOAN', '28', 'ELIAM', '28', 'ADAM', '28', 'URIEL', '28', 'YAIR', '28', 'LUCCAS', '28', 'BRYAN', '28', 'CHRIS', '28', 'MARC', '27', 'BERNARDO', '27', 'ROBERT', '27', 'IBRAHIM', '27', 'TEODORO', '26', 'ANDY', '26', 'MASSIMO', '26', 'NEYTHAN', '26', 'OWEN', '26', 'ERIK', '25', 'ELISEO', '25', 'JHOAN', '25', 'CIRO', '25', 'VLADIMIR', '24', 'EYTHAN', '24', 'BAYRON', '24', 'FRANCESCO', '24', 'JOAO', '24', 'YOEL', '24', 'JAIRO', '24', 'ERIC', '23', 'KILIAN', '23', 'OSVALDO', '23', 'JAIR', '23', 'IHAN', '23', 'JUAQUIN', '23', 'FARID', '23', 'MAEL', '23', 'GIANLUCA', '22', 'IÑIGO', '22', 'FERRÁN', '22', 'ARTHUR', '22', 'NEITHAN', '22', 'JACK', '22', 'ANDREW', '22', 'ERNESTO', '22', 'GERALD', '22', 'WOOD', '22', 'ANTOINE', '21', 'FLAVIO', '21', 'EDISON', '21', 'RENÉ', '21', 'BRAULIO', '21', 'PRINCE', '21', 'BORIS', '21', 'NATHANIEL', '20', 'RAPHAEL', '20', 'JUSTIN', '20', 'TRISTÁN', '20', 'GIULIANO', '20', 'VINCENT', '20', 'LUCIO', '20', 'ADONIS', '20', 'LEO', '20', 'ITHAN', '19', 'APOLO', '19', 'VITTORIO', '19', 'NAIM', '19', 'KARIM', '19', 'ADÁN', '19', 'ALEXANDRO', '19', 'ANTHUAN', '18', 'DIDIER', '18', 'NAWEL', '18', 'AQUILES', '18', 'MAICOL', '18', 'FABRIZIO', '18', 'BALTHAZAR', '18', 'SANTY', '17', 'RYAN', '17', 'RAMÓN', '17', 'ELIEZER', '17', 'NÉSTOR', '17', 'FABRICIO', '17', 'DARIEN', '17', 'JONAS', '17', 'ADAMS', '17', 'JERÓNIMO', '17', 'SALOMÓN', '17', 'YAEL', '16', 'ALLAN', '16', 'ALDO', '16', 'KAI', '16', 'LUCIAN', '16', 'EDER', '16', 'IAM', '16', 'OSTIN', '16', 'BENICIO', '16', 'ZABDIEL', '16', 'ELLIOT', '15', 'XAVIER', '15', 'ELEAZAR', '15', 'ESTEFANO', '15', 'EDWIN', '15', 'GERÓNIMO', '15', 'MARCUS', '15', 'HENRY', '15', 'EDUARD', '15', 'EMERSON', '15', 'JUANPABLO', '14', 'GIOVANNY', '14', 'WLADIMIR', '14', 'LEVI', '14', 'WILSON', '14', 'GIAN', '14', 'AIDAN', '14', 'TYRONE', '14', 'JHAIR', '14', 'NEIZAN', '14', 'ITALO', '14', 'WALTER', '14', 'GIANFRANCO', '14', 'GAMALIEL', '14', 'DASTIN', '14', 'JADIEL', '14', 'ESAI', '14', 'ZAMIR', '13', 'JAEL', '13', 'RONALD', '13', 'ZAHID', '13', 'GREGORIO', '13', 'DONATO', '13', 'ROQUE', '13', 'ZAHIR', '13', 'DASTAN', '13', 'RAMSES', '13', 'ROBINSON', '12', 'ANYELO', '12', 'GIORGIO', '12', 'SAM', '12', 'JOSE-TOMAS', '12', 'OSMAN', '12', 'FIDEL', '12', 'BYRON', '12', 'ILIAN', '12', 'ORLANDO', '12', 'CRISTHIÁN', '12', 'MARLON', '12', 'MIRKO', '12', 'RALPH', '12', 'RAYAN', '12', 'STEFAN', '12', 'TYLER', '12', 'GREGORY', '12', 'JUNIOR', '12', 'JEISON', '12', 'VASCO', '12', 'ROOD', '12', 'NIKOLAS', '12', 'FRANCHESCO', '11', 'TIAGO', '11', 'EREN', '11', 'TOMMY', '11', 'BENITO', '11', 'FRANK', '11', 'DOMINICK', '11', 'ELIOT', '11', 'DEYLAN', '11', 'JEFFERSON', '11', 'ÉTIENNE', '11', 'ANTONY', '11', 'MAIKEL', '11', 'JHONNY', '11', 'NEWEN', '11', 'KEYLOR', '11', 'MAYKOL', '11', 'EITAN', '11', 'MAIKOL', '11', 'EIDER', '11', 'JULIANO', '11', 'KILLIAN', '11', 'ABDIAS', '11', 'CRESCENTE', '11', 'SALVATORE', '11', 'HASSAN', '11', 'RENZO', '11', 'VINCENZO', '10', 'BRUCE', '10', 'RAYMUNDO', '10', 'ALÍ', '10', 'YAMIR', '10', 'MILO', '10', 'ARLEY', '10', 'JOE', '10', 'NEFTALÍ', '10', 'ERWIN', '10', 'IANN', '10', 'STEPHANO', '10', 'MARCIAL', '10', 'SANDRO', '10', 'DAVE', '10', 'DAWENS', '10', 'LENIN', '10', 'BRIAN', '10', 'JADEN', '10', 'YEISON', '10', 'EZRA', '10', 'FILIPPO', '10', 'YULIANO', '10', 'YERIK', '10', 'FRANTZ', '10', 'IVAR', '10', 'YADIEL', '10', 'FRANKO', '10', 'WOODLEY', '10', 'JAHAZIEL', '10', 'ELYAN', '10', 'EDEN', '9', 'PASCAL', '9', 'TAYRON', '9', 'AIDEN', '9', 'NATANIEL', '9', 'JACOBO', '9', 'BAIRON', '9', 'DARWIN', '9', 'JIMMY', '9', 'KALETH', '9', 'ASHER', '9', 'BRADLEY', '9', 'ROGER', '9', 'GERARD', '9', 'JOB', '9', 'GUIDO', '9', 'JAZIEL', '9', 'DAWENSKY', '9', 'YEREMI', '9', 'SANTOS', '9', 'ROY', '9', 'CRISTIANO', '9', 'JHOEL', '9', 'DENZEL', '9', 'LION', '9', 'ARMANDO', '9', 'UZIEL', '9', 'KERVENS', '9', 'ILAN', '9', 'NAHUM', '9', 'MAGDIEL', '9', 'BRANCO', '9', 'SANTHIAGO', '9', 'BERNABÉ', '9', 'AWKÁN', '8', 'NEYMAR', '8', 'STEPHAN', '8', 'JAYSON', '8', 'ROLANDO', '8', 'FAUSTINO', '8', 'DÉNIS', '8', 'ALESSIO', '8', 'TAYLER', '8', 'JASON', '8', 'YORDAN', '8', 'NOAM', '8', 'EDINSON', '8', 'HORACIO', '8', 'NIKOLA', '8', 'PIERRE', '8', 'DANNY', '8', 'AYUN', '8', 'REINALDO', '8', 'BASTHIAN', '8', 'ARIAN', '8', 'ENOC', '8', 'YERAY', '8', 'MIQUEAS', '8', 'DEIVID', '8', 'THOMMAS', '8', 'MATTIAS', '8', 'VIGGO', '8', 'FAUSTO', '8', 'CHRIST', '8', 'RAGNAR', '8', 'FABRIZZIO', '8', 'KAEL', '8', 'GIANCARLO', '8', 'NATHANAEL', '8', 'FRANCIS', '8', 'ROMÉO', '8', 'MATTHEO', '7', 'EUGENIO', '7', 'TRAVIS', '7', 'MILLER', '7', 'GHAEL', '7', 'EDRIC', '7', 'SELIM', '7', 'LÁZARO', '7', 'NOEL', '7', 'ETHIÁN', '7', 'LOVENSKY', '7', 'PANGAL', '7', 'CARLO', '7', 'PHILIPPE', '7', 'MICHEL', '7', 'EMIL', '7', 'POLO', '7', 'ALLEN', '7', 'ABDEL', '7', 'CARLENS', '7', 'DENNIS', '7', 'LOUIS', '7', 'GIORDANO', '7', 'ANKATU', '7', 'CAETANO', '7', 'DANTTE', '7', 'REIMUNDO', '7', 'LUCKAS', '7', 'PELAYO', '7', 'KILIAM', '7', 'GIUSEPPE', '7', 'BRUNNO', '7', 'MATIA', '7', 'FABIANO', '7', 'TAYLOR', '7', 'LIFKO', '7', 'FRANKLIN', '7', 'AZIEL', '7', 'ALAIN', '7', 'JIA', '7', 'YULIAN', '7', 'ENMANUEL', '7', 'CARL', '7', 'GIANLUCAS', '7', 'DAYRON', '7', 'MAXIMILIAN', '7', 'GAHEL', '7', 'WENSLEY', '7', 'DARELL', '7', 'GENARO', '7', 'JUN', '6', 'EFRAÍM', '6', 'NIL', '6']
I was thinking in a def to use names.pop(x) with x as every number of index that is impair, cause the total of str is 1246, so the index quantity is 1247. But although i have tried many times, i cant do it :(
CodePudding user response:
For instance, you can do something like this:
names = ['MATEO', '3869', 'AGUSTIN', '2641']
numbers = []
for string in names:
if string.isnumeric():
numbers.append(string)
>>> numbers
>>> ['3869', '2641']
Or you can use list comprehensions:
numbers = [string for string in names if string.isnumeric()]
CodePudding user response:
You can use a list comprehension:
[item for item in names if item.isnumeric()]
It also appears that the list contains a pattern where there's one name followed by one numeric value. If this is the case, you can use list slicing instead:
names[1::2]
These output (first three / last three elements):
['3869', '2641', '2337', ..., '6', '6', '6']
CodePudding user response:
You can use list comprehension and save its output to a variable, like this:
names = ['MATEO', '3869', 'AGUSTIN', '2641']
numbers = [item for item in names if item.isnumeric()]
>>> numbers
>>> ['3869', '2641']