skip to Main Content

I have list:

itemid = ['113222408782', '113223652945', '113222268092', '113223761722', '113222277037', '113223676589', '113214024190', '113227956444', '113222400375', '113222383960', '113223749386', '113213898511', '113223653433', '113214060057', '113212059543', '113223647852', '113212403974', '113222230789', '113212110156', '113213917508', '113223748917', '113212088893', '113213936773', '113212282559', '113222369037', '113223645004', '113214034011', '113223647208', '113222397481', '113212052765', '113212136602', '113212037895', '113222210185', '113223752305', '113212049744', '113212400978', '113212274566', '113218830085', '113203034623', '113222199167', '113223648988', '113223646543', '113223651519', '113222200831', '113213996789', '113214000484', '113213890605', '113222232853', '113222298617', '113223753658', '113222238111', '113194336951', '113223631876', '113222242464', '113212123303', '113222215450', '113214000567', '113223642160', '113223639750', '113214060070', '113223644511', '113194332243', '113212139900', '113222207007', '113222374260', '113223719876', '113194339799', '113223677943', '113212417158', '113212433693', '113227977319', '113223607151', '113212409228', '113215809743', '113214051350']

This list contains 75 values. I’m cutting this list for 20 items list using following method:

while len(itemid) > 0:
slice = itertools.islice(itemid, 20)
ha = []
for x in slice:
    ha.append(format(x))
    var1 = ','.join(ha)

var1 returns string with 20 values like this:

113222408782,113223652945,113222268092,113223761722,113222277037,113223676589,113214024190,113227956444,113222400375,113222383960,113223749386,113213898511,113223653433,113214060057,113212059543,113223647852,113212403974,113222230789,113212110156,113213917508

And then I got stuck:

I’m using it for eBay api and I want to do the following command:

api_request = {'ItemID': var1}

and it returns:

{'ItemID': '113223748917,113212088893,113213936773,113212282559,113222369037,113223645004,113214034011,113223647208,113222397481,113212052765,113212136602,113212037895,113222210185,113223752305,113212049744,113212400978,113212274566,113218830085,113203034623,113222199167'}

But I need to return the string var1 without quotes like this:

{'ItemID': 113223748917,113212088893,113213936773,113212282559,113222369037,113223645004,113214034011,113223647208,113222397481,113212052765,113212136602,113212037895,113222210185,113223752305,113212049744,113212400978,113212274566,113218830085,113203034623,113222199167}

How can I do this?

2

Answers


  1. The quotes are not actually part of the string, they just signify that it is a string. Therefore you cannot remove them

    Login or Signup to reply.
  2. You does not need to convert array to string, you have to pass the entire object like this:

    var1 = itertools.islice(itemid, 20)
    api_request = {'ItemID': var1}
    

    Why are you trying to cast it to a format if you need to pass it as a array?

    Regards,
    Igor Quirino

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search