Python Forum
Help me with python read file and save file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help me with python read file and save file
#5
Little mental exercise: data cleaning with list comprehension, string methods and indexing:

In [1]: lst = [ 
   ...: '"1":"[email protected]","p":"password1","r":"PYTHON DEMO OUTPUT","d":"yahoo.com"',
   ...: '"2":"[email protected]","p":"password2","r":"PYTHON DEMO OUTPUT","d":"mail.bg"',
   ...: '"3":"[email protected]","p":"password3","r":"PYTHON DEMO OUTPUT,"d":"ya.ru"'
   ...: ]

In [2]: [row.split(':')[i].split(',')[0].strip('"') for row in lst for i in [1, 2, 4]]
Out[3]: 
['[email protected]',
 'password1',
 'yahoo.com',
 '[email protected]',
 'password2',
 'mail.bg',
 '[email protected]',
 'password3',
 'ya.ru'] 
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
RE: Help me with python read file and save file - by perfringo - Apr-02-2019, 06:56 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to remove unwanted images and tables from a Word file using Python? rownong 2 712 Feb-04-2025, 08:30 AM
Last Post: Pedroski55
  Best way to feed python script of a file absolut 6 1,047 Jan-11-2025, 07:03 AM
Last Post: Gribouillis
  Removal of watermark logo pdf file Python druva 0 642 Jan-01-2025, 11:55 AM
Last Post: druva
  How to write variable in a python file then import it in another python file? tatahuft 4 866 Jan-01-2025, 12:18 AM
Last Post: Skaperen
  How to communicate between scripts in python via shared file? daiboonchu 4 1,493 Dec-31-2024, 01:56 PM
Last Post: Pedroski55
  Problems writing a large text file in python Vilius 4 952 Dec-21-2024, 09:20 AM
Last Post: Pedroski55
  How to read a file as binary or hex "string" so that I can do regex search? tatahuft 3 995 Dec-19-2024, 11:57 AM
Last Post: snippsat
  How to re-register .py file extension to new moved Python dir (on Windows)? pstein 5 1,245 Nov-06-2024, 03:06 PM
Last Post: DeaD_EyE
  Read TXT file in Pandas and save to Parquet zinho 2 1,204 Sep-15-2024, 06:14 PM
Last Post: zinho
  JSON File - extract only the data in a nested array for CSV file shwfgd 2 1,024 Aug-26-2024, 10:14 PM
Last Post: shwfgd

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020