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
  Connecting to Remote Server to read contents of a file ChaitanyaSharma 1 259 May-03-2024, 07:23 AM
Last Post: Pedroski55
  Python openyxl not updating Excel file MrBean12 1 394 Mar-03-2024, 12:16 AM
Last Post: MrBean12
  Python logging RotatingFileHandler writes to random file after the first log rotation rawatg 0 454 Feb-15-2024, 11:15 AM
Last Post: rawatg
  Open/save file on Android frohr 0 363 Jan-24-2024, 06:28 PM
Last Post: frohr
  connect sql by python using txt. file dawid294 2 489 Jan-12-2024, 08:54 PM
Last Post: deanhystad
  file open "file not found error" shanoger 8 1,269 Dec-14-2023, 08:03 AM
Last Post: shanoger
  Recommended way to read/create PDF file? Winfried 3 2,963 Nov-26-2023, 07:51 AM
Last Post: Pedroski55
  python Read each xlsx file and write it into csv with pipe delimiter mg24 4 1,586 Nov-09-2023, 10:56 AM
Last Post: mg24
  how to save to multiple locations during save cubangt 1 592 Oct-23-2023, 10:16 PM
Last Post: deanhystad
  Replace a text/word in docx file using Python Devan 4 3,701 Oct-17-2023, 06:03 PM
Last Post: Devan

Forum Jump:

User Panel Messages

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