Questions on lists, the range function & concatenation

  • (2 Pages)
  • +
  • 1
  • 2

21 Replies - 1754 Views - Last Post: 25 January 2018 - 07:38 AM Rate Topic: -----

#16 fad3r  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 27
  • Joined: 22-January 18

Re: Questions on lists, the range function & concatenation

Posted 24 January 2018 - 02:47 PM

Hello again.

I have gotten the first part of the problem done with everyone's help. I am now working on creating the dictionary and I am getting an error from Python I dont understand how to read.

Here is how i tried to create the dictionary

import string
letlist = list(string.ascii_lowercase)
#print (letlist)

#Create string of letters
letstring = string.ascii_lowercase
#print (letstring)

#Create list of numbers
form = ":"
list1=[]
for i in range (1, 27):
    i = str(i) + form
    list1.append(i)
#print (list1)
zipped = zip (list1, letlist)
print (zipped)




I thought that if I formatted strings correctly I could just use zip to merge them.

Is it not possible to edit posts?

Here is the error message from the program

<zip object at 0x00000186D8AFE048>
Was This Post Helpful? 0
  • +
  • -

#17 andrewsw  Icon User is offline

  • blow up my boots
  • member icon

Reputation: 6500
  • View blog
  • Posts: 26,286
  • Joined: 12-December 12

Re: Questions on lists, the range function & concatenation

Posted 24 January 2018 - 02:54 PM

That is not an error message, it is the available string representation of the object you are trying to print. You'll probably need to iterate the elements of zipped (to expand it) to discover what it contains.
Was This Post Helpful? 1
  • +
  • -

#18 fad3r  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 27
  • Joined: 22-January 18

Re: Questions on lists, the range function & concatenation

Posted 24 January 2018 - 03:18 PM

I have now solved the first part. Thank you again for all the help. I have learned a lot.

Here is the code for anyone that is interested. The next step is to learn to merge a string and a list to create a new dictionary. I will work on that now and ask questions once i get stuck.

import string
letlist = list(string.ascii_lowercase)
#print (letlist)

#Create string of letters
letstring = string.ascii_lowercase
#print (letstring)

#Create list of numbers
list1=[]
for i in range (1, 27):
    list1.append(i)
#print (list1)

#Create dictionary for part 1
zipped =dict(zip(list1,letlist))
print (zipped)



Was This Post Helpful? 0
  • +
  • -

#19 ndc85430  Icon User is offline

  • I think you'll find it's "Dr"
  • member icon

Reputation: 703
  • View blog
  • Posts: 2,877
  • Joined: 13-June 14

Re: Questions on lists, the range function & concatenation

Posted 24 January 2018 - 03:57 PM

You're already doing the merging, with zip. As mentioned above, you'll need to iterate over zipped and print each of the items. The reason again is that zip returns a thing you need to iterate over to get the items inside it (there are reasons why it's beneficial to use this sort of idea, but those probably aren't too important to go into right now).
Was This Post Helpful? 1
  • +
  • -

#20 fad3r  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 27
  • Joined: 22-January 18

Re: Questions on lists, the range function & concatenation

Posted 25 January 2018 - 04:56 AM

View Postndc85430, on 24 January 2018 - 03:57 PM, said:

You're already doing the merging, with zip. As mentioned above, you'll need to iterate over zipped and print each of the items. The reason again is that zip returns a thing you need to iterate over to get the items inside it (there are reasons why it's beneficial to use this sort of idea, but those probably aren't too important to go into right now).


I don't understand this answer clearly. Part of what the challenge is challenge work. Meaning it is not something I would do in real life. For example taking a string and turning it into a dictionary. In real life I think would convert the string into a list and then use zip like I did in the first part.

For the second part I am not sure how I take this string and then loop through it to create the dictionary. I thought zip only took lists as arguments.

Thanks again everyone these last 2 days have been awesome. I also signed up for dataquest & codeacademy to try to get up to speed faster.
Was This Post Helpful? 0
  • +
  • -

#21 ndc85430  Icon User is offline

  • I think you'll find it's "Dr"
  • member icon

Reputation: 703
  • View blog
  • Posts: 2,877
  • Joined: 13-June 14

Re: Questions on lists, the range function & concatenation

Posted 25 January 2018 - 06:37 AM

I haven't got too much time to reply right now, since I need to get back to work, but zip takes iterables as arguments. A list is a kind of iterable, as are strings, tuples, dicts and other things. Actually, my answer was more about what zip returns - it doesn't return a list, but something else you can iterate over.
Was This Post Helpful? 1
  • +
  • -

#22 fad3r  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 27
  • Joined: 22-January 18

Re: Questions on lists, the range function & concatenation

Posted 25 January 2018 - 07:38 AM

That did indeed solve it. Thank you. I am on to the last part of trying to iterate through a dict and only pulling out the even and odd ones. I will update once I have it finished or hit a roadblock.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2