regex - Python - Seperate alphanumeric list into integer and string -


i trying manipulate csv file containing data this:

['193t','4234234234'],['30t','54353456346'],['203k','4234234234'],['19e','4234234234'] 

the alphanumeric string should separated number , single character , put array int() , string already. second step cluster of same characters , sort them integer.

ending this:

[19,'e',4234234234],[203,'k',4234234234],[30,'t',54353456346],[193,'t',4234234234] 

i hope can grasp idea behind it.

thank in advance.

l = [['193t','4234234234'],      ['30t','54353456346'],      ['203k','4234234234'],      ['19e','4234234234']]  # using list comprehension [[int(i[0][:-1]), i[0][-1], int(i[1])] in l] 

output

[[193, 't', 4234234234],  [30, 't', 54353456346],  [203, 'k', 4234234234],  [19, 'e', 4234234234]] 

then can sort using second element key.

sorted([[int(i[0][:-1]), i[0][-1], int(i[1])] in l], key = lambda x: x[1]) 

output

[[19, 'e', 4234234234l],  [203, 'k', 4234234234l],  [193, 't', 4234234234l],  [30, 't', 54353456346l]] 

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -