Python Forum
Split List and Sublist from Pyodbc
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Split List and Sublist from Pyodbc
#2
The result you're showing is a list of tuples
so something like (you can build your lists from this (replace print with list creation code):
Decimal = float
results = [
    (Decimal('28000.0000'), 2010, 272), (Decimal('308000.0000'), 2011, 272),
    (Decimal('582000.0000'), 2012, 272), (Decimal('387000.0000'), 2013, 272),
    (Decimal('367000.0000'), 2010, 281), (Decimal('3037000.0000'), 2011, 281),
    (Decimal('4822000.0000'), 2012, 281), (Decimal('2936000.0000'), 2013, 281),
    (Decimal('637000.0000'), 2010, 282), (Decimal('3440000.0000'), 2011, 282),
    (Decimal('4415000.0000'), 2012, 282), (Decimal('3294000.0000'), 2013, 282),
    (Decimal('478000.0000'), 2010, 296), (Decimal('1209000.0000'), 2011, 296),
    (Decimal('478000.0000'), 2012, 296), (Decimal('1209000.0000'), 2013, 296)
]

for decimal, year, employee_id in results:
    print(f'\ndecimal: {decimal}\nYear: {year}\nEmployeeId: {employee_id}')
output:
Output:
decimal: 28000.0 Year: 2010 EmployeeId: 272 decimal: 308000.0 Year: 2011 EmployeeId: 272 decimal: 582000.0 Year: 2012 EmployeeId: 272 decimal: 387000.0 Year: 2013 EmployeeId: 272 decimal: 367000.0 Year: 2010 EmployeeId: 281 decimal: 3037000.0 Year: 2011 EmployeeId: 281 decimal: 4822000.0 Year: 2012 EmployeeId: 281 decimal: 2936000.0 Year: 2013 EmployeeId: 281 decimal: 637000.0 Year: 2010 EmployeeId: 282 decimal: 3440000.0 Year: 2011 EmployeeId: 282 decimal: 4415000.0 Year: 2012 EmployeeId: 282 decimal: 3294000.0 Year: 2013 EmployeeId: 282 decimal: 478000.0 Year: 2010 EmployeeId: 296 decimal: 1209000.0 Year: 2011 EmployeeId: 296 decimal: 478000.0 Year: 2012 EmployeeId: 296 decimal: 1209000.0 Year: 2013 EmployeeId: 296
Reply


Messages In This Thread
Split List and Sublist from Pyodbc - by parthi1705 - May-05-2019, 10:22 AM
RE: Split List and Sublist from Pyodbc - by Larz60+ - May-05-2019, 10:44 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Using pyodbc&pandas to load a Table data to df tester_V 3 2,764 Sep-09-2023, 08:55 PM
Last Post: tester_V
  [split] why can't i create a list of numbers (ints) with random.randrange() astral_travel 7 2,785 Oct-23-2022, 11:13 PM
Last Post: Pedroski55
  Split string using variable found in a list japo85 2 2,140 Jul-11-2022, 08:52 AM
Last Post: japo85
  pyodbc gmerritt 8 4,909 Feb-21-2022, 07:21 PM
Last Post: gmerritt
  Use one list as search key for another list with sublist of list jc4d 4 3,058 Jan-11-2022, 12:10 PM
Last Post: jc4d
Question Sublist/ Subarray into string Python SantiagoPB 2 2,847 Apr-23-2021, 07:03 PM
Last Post: SantiagoPB
  Formatting Data/Time with Pyodbc and openpyxl bearcats6001 0 2,998 Aug-17-2020, 03:44 PM
Last Post: bearcats6001
  Get database used data space from pyodbc susja 1 3,027 Aug-14-2020, 02:01 PM
Last Post: susja
  List of objects with sublist medatib531 4 3,282 Mar-01-2020, 06:16 PM
Last Post: buran
  [split] question about list comprehension Armin 17 8,236 Jan-29-2020, 04:32 PM
Last Post: Clunk_Head

Forum Jump:

User Panel Messages

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