Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8392007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:24:24+00:00 2026-06-09T19:24:24+00:00

Sorry for my english I have a list like: [[‘string type’,’short int type’,’long int

  • 0

Sorry for my english

I have a list like:

[['string type','short int type','long int type','string type','float'],
['Stackoverflow','32','0','any stringgg','55.0'],
['anystring','16','1654657987984','striiingg','2.5']]

I call:

['string type','short int type','long int type','string type','float']

is the first sub-list
and

['Stackoverflow','32','0','any stringgg','55.0']

is the second sub-list, same for the three sub-list

How can I use struct.pack() data in the second & third sub-lists based on the type of the first sub-list?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T19:24:25+00:00Added an answer on June 9, 2026 at 7:24 pm

    You could do something like this (quickly coded, could use some work)

    import struct
    
    type_map = {
            'string type': 's',
            'short int type': 'h',
            'long int type': 'q',
            'float': 'f'
            }
    
    conversion = {
            's': str,
            'h': int,
            'q': int,
            'f': float
            }
    
    
    def do_pack(types, data):
        if len(types) != len(data):
            raise Excpetion("wrong lengths")
        packing = '<'
        data_iter = []
        for i, struct_type in enumerate(types):
            t = type_map[struct_type]
            if t == 's':
                packing += '%ds' % len(data[i]) 
                data_iter.append(data[i])
            else:
                packing += t
                data_iter.append(conversion[t](data[i]))
        return struct.pack(packing, *data_iter), packing
    
    packer = [['string type','short int type','long int type','string type','float'],['Stackoverflow','32','0','any stringgg','55.0'],['anystring','16','1654657987984','striiingg','2.5']]
    
    types = packer[0]
    for data_set in packer[1:]:
        binary, packing = do_pack(types, data_set)
        print struct.unpack(packing, binary)
    

    OUTPUT

    ('Stackoverflow', 32, 0, 'any stringgg', 55.0)
    ('anystring', 16, 1654657987984, 'striiingg', 2.5)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry for my bad English. Just like what I asked. I have this class
Sorry for my English. I have my own ArrayAdapter for list activity . My
First of all, sorry for my English... I have something like this: public class
Sorry ,my English is poor, I have never speak English after I leave the
Sorry for bad english and bad title! I have the table post id title
sorry about input mistakes, english its not my mother lang. I have this code
First, sorry for my bad english, I'm French. Here the problem : I have
First of all sorry for my English. I would like to use a backtracking
(First of all, sorry for my english, it's not my first language) I have
First, im sorry to my bad english :). My object have one variable of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.