473,388 Members | 1,188 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

for loop for list of string without using replace how to edit ?

shahjapan
I have this list,

['nl_NL.csv', 'es_ES.csv', 'pt_BR.csv', 'pt_PT.csv', 'cs_CZ.csv', 'zh_TW.csv', 'de_DE.csv', 'ro_RO.csv', 'zh_CN.csv', 'es_AR.csv', 'it_IT.csv', 'sv_SE.csv', 'ru_RU.csv', 'hu_HU.csv']


and I want this

['es_ES', 'pt_BR', 'pt_PT', 'cs_CZ', 'zh_TW', 'fr_FR', 'de_DE', 'ro_RO', 'zh_CN', 'es_AR', 'it_IT', 'sv_SE', 'ru_RU', 'hu_HU']

can anyone has optimized code for python for the same ?
Feb 26 '08 #1
2 1212
bvdet
2,851 Expert Mod 2GB
I have this list,

['nl_NL.csv', 'es_ES.csv', 'pt_BR.csv', 'pt_PT.csv', 'cs_CZ.csv', 'zh_TW.csv', 'de_DE.csv', 'ro_RO.csv', 'zh_CN.csv', 'es_AR.csv', 'it_IT.csv', 'sv_SE.csv', 'ru_RU.csv', 'hu_HU.csv']


and I want this

['es_ES', 'pt_BR', 'pt_PT', 'cs_CZ', 'zh_TW', 'fr_FR', 'de_DE', 'ro_RO', 'zh_CN', 'es_AR', 'it_IT', 'sv_SE', 'ru_RU', 'hu_HU']

can anyone has optimized code for python for the same ?
This truncates the file names:
Expand|Select|Wrap|Line Numbers
  1. # csvlist is your initial list
  2. >>> [item.split('.')[0] for item in csvlist]
  3. ['nl_NL', 'es_ES', 'pt_BR', 'pt_PT', 'cs_CZ', 'zh_TW', 'de_DE', 'ro_RO', 'zh_CN', 'es_AR', 'it_IT', 'sv_SE', 'ru_RU', 'hu_HU']
  4. >>> 
Feb 26 '08 #2
jlm699
314 100+
Or alternately:

Expand|Select|Wrap|Line Numbers
  1. >>> csvlist = ['nl_NL.csv', 'es_ES.csv', 'pt_BR.csv', 'pt_PT.csv', 'cs_CZ.csv', 'zh_TW.csv', 'de_DE.csv', 'ro_RO.csv', 'zh_CN.csv', 'es_AR.csv', 'it_IT.csv', 'sv_SE.csv', 'ru_RU.csv', 'hu_HU.csv']
  2. >>> newlist = [item.rstrip('.csv') for item in csvlist]
  3. >>> newlist
  4. ['nl_NL', 'es_ES', 'pt_BR', 'pt_PT', 'cs_CZ', 'zh_TW', 'de_DE', 'ro_RO', 'zh_CN', 'es_AR', 'it_IT', 'sv_SE', 'ru_RU', 'hu_HU']
  5.  
Same thing basically...
Feb 26 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Steve | last post by:
Hi, I'm getting some output by running a command using os.popen. I need to parse the output and transform it in some sense so that it's 'DB compatible', (i.e I need to store the output in a...
6
by: ALthePal | last post by:
Hi, I'm not sure if we are able to or even how to loop through the web forms in a VB.NET project during design time. In MSAccess we are able to go through the database -> forms collection and...
10
by: Ronny Sigo | last post by:
Hello all, Could anybody give me the correct syntax for defining a loop using the form's recordset for as long as it is not at the end of the table ? example: Do While not EOF ' this is the...
16
by: Jen | last post by:
Hi. I have this problem that I think should be easy but have been struggling with this for days. I have a list based on a recordset from a database. This list consists of records meeting a certain...
0
by: weiwei | last post by:
Hi here is my scenario, I create a drop down list in itemtemplate.(that drop down is created from db), after user click edit command, my ideal plan is have another drop down list in...
1
by: Doug_J_W | last post by:
I have a Visual Basic (2005) project that contains around twenty embedded text files as resources. The text files contain two columns of real numbers that are separated by tab deliminator, and are...
2
by: rn5a | last post by:
In a ASP applicatiuon, the FOrm has a textbox & a select list where the admin can select multiple options. Basically the admin has to enter the name of a new coach in the textbox & select the...
8
by: SaltyBoat | last post by:
Needing to import and parse data from a large PDF file into an Access 2002 table: I start by converted the PDF file to a html file. Then I read this html text file, line by line, into a table...
7
by: Grok | last post by:
I need an elegant way to remove any characters in a string if they are not in an allowed char list. The part cleaning files of the non-allowed characters will run as a service, so no forms here. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.