Results 1 to 2 of 2

Thread: Formula for extracting certain elements from a list

  1. #1
    Join Date
    Jan 2017
    Posts
    54
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Formula for extracting certain elements from a list

    I need a formula to iterate through list A and extract certain items and put into list B. I need to skip two items, extract the next three, skip two items, extract the next three, etc:

    Qt Code:
    1. A = (34, 35, 40, 41, 42, 22, 34, 43, 44, 45, 65, 78, 46, 47, 48)
    To copy to clipboard, switch view to plain text mode 

    I want:
    Qt Code:
    1. B = (40, 41, 42, 43, 44, 45, 46, 47, 48)
    To copy to clipboard, switch view to plain text mode 

    this is all I could get:
    Qt Code:
    1. for i, val in enumerate(A):
    2. B = (
    To copy to clipboard, switch view to plain text mode 


    thanks

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,236
    Thanks
    303
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Formula for extracting certain elements from a list

    In pseudocode, assuming "i" is the index of the item in the list and i starts at 0:

    Qt Code:
    1. if i % 5 < 2, skip
    2. else extract
    To copy to clipboard, switch view to plain text mode 

    You should be able to do that in python. "%" is the "remainder" operator - it divides the left side by the right side and returns the remainder. If it isn't the same in python, I am sure there is a similar operator or function that does the same.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. The following user says thank you to d_stranz for this useful post:

    dennisvz (20th July 2019)

Similar Threads

  1. Understanding QColor's Grayscale formula
    By bpetty in forum Qt Programming
    Replies: 3
    Last Post: 23rd June 2019, 07:34
  2. Self-extracting archive
    By atomic in forum Qt Programming
    Replies: 7
    Last Post: 8th April 2015, 21:55
  3. Number of elements in a list of list
    By giorgik in forum General Programming
    Replies: 5
    Last Post: 18th July 2013, 08:36
  4. List all elements of a QTreeWidget from top to bottom
    By ricardosf in forum Qt Programming
    Replies: 2
    Last Post: 12th June 2010, 02:46
  5. Extracting strings in files
    By ComaWhite in forum Qt Programming
    Replies: 2
    Last Post: 7th October 2008, 00:01

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.