Day 15 of 100DaysofCode: A Dummy Project To Find Numbers Of Fraud Voters
Tags: 100daysofcode, codenewbie, beginners, python
Published: 2021-01-08 14:55:47

Today is my 15 day of #100DaysofCode. Today I learned more properties of CSS among them some are avoid colorblindness issues by using sufficient contrast, avoid colorblindness issues by carefully choosing colors that convey information, give links meaning by using descriptive link text, use tabindex to add keyboard to an element etc on [Freecodecamp.](https://www.freecodecamp.org/learn/responsive-web-design/responsive-web-design-principles/)

Also I learned more about python access on web data from [coursera.](https://www.coursera.org/learn/python-network-data/lecture/MbRIS/12-3-unicode-characters-and-strings) Did some code regarding to python. I did one project to find the numbers of total voters, unique voters, fraud voters, voters who voted more than once.

# Code To Find Numbers Of Fraud Voters 
My challenge is given below.
``` 
## Challenge 1
You worked hard to get a government job but it is part time only and if you did well, then there is a high chance of getting a permanent placement. And you are assigned to one task. As trainee, you have nothing hard task but a boring one. 
You are assigned to a vote counting board and you have to count valid votes. 

After looking at the past data, you knew that there has been irregularities on vote counting. Some corrupt politician feeds some money to do revote on themself. And the previous authorities didn't knew about that but lucky you, did and this is going to one hell of a promotion. So you knew that, there are 5 parties, A, B, C, D and E and a person's name, age and citizenship id. And there are only few chances that same person has similar name, age and citizenship id. So you will have data like below:
```

```text
Ram Lama,29,2030-03-01-055,A
Judda Thapa,19,2040-03-01-055,B
Haris Lama,29,2030-03-03-055,B
Aakriti Tiwari,39,2023-03-01-055,C
Ramesh Shah,22,2031-03-01-034,D
Ram Lama,29,2030-03-01-055,A
```

``` Problem 1:  Find out how many valid votes there has been?```
I started with reading file.This way, file is read as one file pointer and it is closed automatically.

```python
with open("vote 1.txt", "r") as fp:
    lines = fp.readlines()
    lines

```
And I used `len()` to find total voters. For unique voters I used `len(set())` this gives non repeated value. After that it is easy to find fraud voters by subtracting total voters with unique voters.
```python
print(f"Total  {len(lines)} votes.")
print(f"Total {len(set(lines))} unique votes.")
print(f"There are {len(lines)-len(set(lines))} fraud votes.")
```
```Problem 2 Who voted more than once?```
To find the voters who voted more than once I build one set. There is loop. If count of items more than once then kept in repeated-items. I built a empty dictionary to keep the voters name as key and how many times they voted as value. And my  program is given below in my code.
```python
# Who voted more than once
repeated_items = set()
for item in lines:
    if lines.count(item)>1:
        repeated_items.add(item)
#print(repeated_items)

occurance = {}

for item in lines:
    if occurance.get(item):
        occurance[item]+=1
    else:
        occurance[item]=1
nd = {k: v for k, v in list(reversed(sorted(occurance.items(), key=lambda item: item[1])))}
nd

```
<blockquote class="twitter-tweet"><p lang="en" dir="ltr">Day 15 of <a href="https://twitter.com/hashtag/100DaysOfCode?src=hash&amp;ref_src=twsrc%5Etfw">#100DaysOfCode</a> and <a href="https://twitter.com/hashtag/Python?src=hash&amp;ref_src=twsrc%5Etfw">#Python</a> <br>* Worked on more properties of CSS on Freecodecamp<br>* Learned about python access on web data on coursera<br>* Python code to find total voters, fraud voters, unique voters, voters who voted more than once from dummy voting data <a href="https://t.co/9Nj8Yh7nML">pic.twitter.com/9Nj8Yh7nML</a></p>&mdash; Durga Pokharel (@mathdurga) <a href="https://twitter.com/mathdurga/status/1347549415012069383?ref_src=twsrc%5Etfw">January 8, 2021</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>