my net house

WAHEGURU….!

Python list thing. (INdex out of range)

most of hte time I forget this thing and consumes my time.

if I have a list:

a = [‘435 456 123 334 769’]

print a[0]

will give output same as – > [‘435 456 123 334 769’]

but if i run print a[1] it will return Index Out of range. Obvious thing….

So what I do to solve this

for numbers in a[0].split():

print number

Which gives me exact thing I need. Actually split() function splits all the elements of list in the given index.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: