Dictionary help

K

kjakupak

So let's say I have a file and it looks like this:
Title 1: item
Title 2: item
etc

Is it possible to use a dictionary for something like the input above? Because I want to be able to use the input above to delete the "Title 1" and "Title 2" but still show the items (on separate lines).
Basically I want it to just show:
item
item
etc..

What I've got is
dict(item.split(":") for item in cInfo.split(" "))

Where cInfo is a function that extracts the first 5 lines of a file
 
T

Tim Chase

So let's say I have a file and it looks like this:
Title 1: item
Title 2: item
etc

Is it possible to use a dictionary for something like the input
above? Because I want to be able to use the input above to delete
the "Title 1" and "Title 2" but still show the items (on separate
lines). Basically I want it to just show: item item
etc..

What I've got is
dict(item.split(":") for item in cInfo.split(" "))

Where cInfo is a function that extracts the first 5 lines of a file

It sounds like all you need is some basic string functions, not a
dictionary:

for line in file('input.txt'):
title, _, item = line.partition(':')
print(item.strip())

-tkc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top