Python Forum
Split the list and obtain a single value
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Split the list and obtain a single value
#2
I've never used sqlparse before. Nevertheless, exploring its source code might lead to the following solution, e.g.
import sqlparse
from sqlparse.tokens import Token  # look at source of tokens.py
raw = 'select * from foo; select * from bar;'
parsed = sqlparse.parse(raw)
list(filter(lambda x: x.ttype in [Token.Keyword, Token.Keyword.DML], parsed[0].tokens))
Output:
[<DML 'select' at 0x7F732037EEE8>, <Keyword 'from' at 0x7F732039F0A8>]
Reply


Messages In This Thread
RE: Split the list and obtain a single value - by scidam - Jul-12-2019, 12:01 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Resampling: How do I obtain the value of the last week of the month? JaneTan 2 973 Dec-12-2022, 12:49 AM
Last Post: JaneTan
  [split] why can't i create a list of numbers (ints) with random.randrange() astral_travel 7 1,430 Oct-23-2022, 11:13 PM
Last Post: Pedroski55
  How to split the input taken from user into a single character? mHosseinDS86 3 1,137 Aug-17-2022, 12:43 PM
Last Post: Pedroski55
  Split string using variable found in a list japo85 2 1,238 Jul-11-2022, 08:52 AM
Last Post: japo85
  Split single column to multiple columns SriRajesh 1 1,290 Jan-07-2022, 06:43 PM
Last Post: jefsummers
  Parse String between 2 Delimiters and add as single list items lastyle 5 3,284 Apr-11-2021, 11:03 PM
Last Post: lastyle
  convert List with dictionaries to a single dictionary iamaghost 3 2,802 Jan-22-2021, 03:56 PM
Last Post: iamaghost
  How to append multiple <class 'str'> into a single List ahmedwaqas92 2 2,275 Jan-07-2021, 08:17 AM
Last Post: ahmedwaqas92
  Undo interation to make a single list? DustinKlent 2 2,133 Nov-29-2020, 03:41 AM
Last Post: DustinKlent
  unique (single) value in dict (or list) 3Pinter 5 2,404 Mar-27-2020, 12:55 PM
Last Post: 3Pinter

Forum Jump:

User Panel Messages

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