1 Replies - 364 Views - Last Post: 23 January 2012 - 09:46 AM Rate Topic: -----

Topic Sponsor:

#1 jone kim  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 30
  • Joined: 07-January 10

PYTHON: CHECK FOR EMPTY INDEXES AND FILL WITH INPUT IN THE LIST

Posted 23 January 2012 - 09:42 AM

list1 is of empty strings. Now I've to fill this empty list with A's.

1. check if the list is empty or not

list1 = [' ',' ',' ',' ',' ',' ',' ',' ',' ']
 def check_emptystring(list1)
	for i in range(len(list1)):
		if list1[i] == ' ':
			print('list is not full')



2. make a new list "list2" as the list of indexes that are empty strings of list1 and send input A one by one. for example,after filling list1 with A's

list1 = ['A','A','','A','','','','A','']

now I've to create a new list "list2" as the indexes of empty strings in list1, so:
list2=[3,5,6,7,9]


def get_empytlist1(list1):
	list2 = []
	for i in range(len(list1)):
		if list1[i] == ' ':
			list2.append(i)
	return list2



now I've to fill at these empty indexes of list1 with A's one by one. How can i do it???

Is This A Good Question/Topic? 0
  • +

Replies To: PYTHON: CHECK FOR EMPTY INDEXES AND FILL WITH INPUT IN THE LIST

#2 Motoma  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 443
  • View blog
  • Posts: 792
  • Joined: 08-June 10

Re: PYTHON: CHECK FOR EMPTY INDEXES AND FILL WITH INPUT IN THE LIST

Posted 23 January 2012 - 09:46 AM

Something like this:
for index in list2:
    list1[index] = 'A'


This post has been edited by Motoma: 23 January 2012 - 09:46 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1