Python Forum
The list length should be 100 but it is more than 100
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
The list length should be 100 but it is more than 100
#1
Hello,

I am trying to produce 100 different names (names should be unique) and I wrote this simple code:

import names
parties=[]
nss=100
while len(parties) < nss:
     for i in range(nss):
        rand_name = names.get_first_name(gender='female')
        if rand_name not in parties:
           parties.append(rand_name)
           
print(parties)
print(len(parties))
But I have more than 100 names at the end. What am I missing in this code?
Reply
#2
okay. This for is not necessery here.
It is sorted out
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  converting list of zero length to a matrix of 3*3 vp1989 2 1,891 May-20-2020, 07:46 PM
Last Post: deanhystad
  List Comprehension - Creating a list of the length of an item help paul41 2 2,015 Nov-18-2019, 10:21 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020