1

I have the following response I am getting when I for loop through the following:

for col in ids:

        print (format(col)),
    print ("\n")
    print type(ids[0])

I have a tuple that has element of different type: unicode, and int.

(u'0021401225', u'0021401203', u'0021401167', u'0021401148', u'0021401124', u'0021401092', u'0021401078', u'0021401066', u'0021401037', u'0021401023', u'0021401005', u'0021400995', u'0021400985', u'0021400964', u'0021400948', u'0021400924', u'0021400915', u'0021400900', u'0021400891', u'0021400854', u'0021400839', u'0021400821', u'0021400809', u'0021400800', u'0021400796', u'0021400766', u'0021400747', u'0021400743', u'0021400718', u'0021400711', u'0021400700', u'0021400681', u'0021400676', u'0021400658', u'0021400643', u'0021400626', u'0021400620', u'0021400599', u'0021400586', u'0021400570', u'0021400561', u'0021400547', u'0021400523', u'0021400503', u'0021400484', u'0021400479', u'0021400466', u'0021400429', u'0021400416', u'0021400401', u'0021400386', u'0021400370', u'0021400355', u'0021400336', u'0021400326', u'0021400308', u'0021400303', u'0021400281', u'0021400273', u'0021400253', u'0021400238', u'0021400211', u'0021400199', u'0021400186', u'0021400179', u'0021400159', u'0021400147', u'0021400133', u'0021400125', u'0021400098', u'0021400081', u'0021400066', u'0021400055', u'0021400022', u'0021400018')

I'm trying to store these values without the

u'

Because I can key off of these id's later in my program. But I just want to store them as integers which might look like the below:

[('0021401225','0021401203', '0021401167', '0021401148','0021401124', '0021401092', '0021401078', '0021401066', '0021401037', '0021401023')]

I would like to for-loop through them.

2
  • The u prefix indicates you have an unicode character string, rather than a byte string. Both types will work equally well as a key. You can convert them to actual integers using the answer below but by using int instead of str. Commented Oct 8, 2015 at 23:41
  • don't use repr(some_tuple) as your storage format. You could use json instead: json.dumps(some_tuple) Commented Oct 9, 2015 at 9:52

1 Answer 1

2
lt = (u'0021401225', u'0021401203', u'0021401167', u'0021401148', u'0021401124', u'0021401092', u'0021401078', u'0021401066', u'0021401037', u'0021401023', u'0021401005', u'0021400995', u'0021400985', u'0021400964', u'0021400948', u'0021400924', u'0021400915', u'0021400900', u'0021400891', u'0021400854', u'0021400839', u'0021400821', u'0021400809', u'0021400800', u'0021400796', u'0021400766', u'0021400747', u'0021400743', u'0021400718', u'0021400711', u'0021400700', u'0021400681', u'0021400676', u'0021400658', u'0021400643', u'0021400626', u'0021400620', u'0021400599', u'0021400586', u'0021400570', u'0021400561', u'0021400547', u'0021400523', u'0021400503', u'0021400484', u'0021400479', u'0021400466', u'0021400429', u'0021400416', u'0021400401', u'0021400386', u'0021400370', u'0021400355', u'0021400336', u'0021400326', u'0021400308', u'0021400303', u'0021400281', u'0021400273', u'0021400253', u'0021400238', u'0021400211', u'0021400199', u'0021400186', u'0021400179', u'0021400159', u'0021400147', u'0021400133', u'0021400125', u'0021400098', u'0021400081', u'0021400066', u'0021400055', u'0021400022', u'0021400018')

lt = list(map(str,lt) )

print(lt)

['0021401225', '0021401203', '0021401167', '0021401148', '0021401124', '0021401092', '0021401078', '0021401066', '0021401037', '0021401023', '0021401005', '0021400995', '0021400985', '0021400964', '0021400948', '0021400924', '0021400915', '0021400900', '0021400891', '0021400854', '0021400839', '0021400821', '0021400809', '0021400800', '0021400796', '0021400766', '0021400747', '0021400743', '0021400718', '0021400711', '0021400700', '0021400681', '0021400676', '0021400658', '0021400643', '0021400626', '0021400620', '0021400599', '0021400586', '0021400570', '0021400561', '0021400547', '0021400523', '0021400503', '0021400484', '0021400479', '0021400466', '0021400429', '0021400416', '0021400401', '0021400386', '0021400370', '0021400355', '0021400336', '0021400326', '0021400308', '0021400303', '0021400281', '0021400273', '0021400253', '0021400238', '0021400211', '0021400199', '0021400186', '0021400179', '0021400159', '0021400147', '0021400133', '0021400125', '0021400098', '0021400081', '0021400066', '0021400055', '0021400022', '0021400018']
Sign up to request clarification or add additional context in comments.

1 Comment

It works! Thank you! So when I print lt, it will be formatted as a list?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.