Python Forum

Full Version: Dont know How
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi
A bash script helper create a file for my python script posted here

The 24_hour file is some thing like this:

24_hour:
ETH:100
ZEN:100
ZEC:99
DGB:45
ETH:100
ZEN:102
ZEC:93
DGB:44
ZEN:102
ZEN:104
ZEN:105
ZEN:102
ZEN:106
ZEN:108
ZEN:125
ZEN:132
ZEN:135
ZEN:105
DGB:44
DGB:43
DGB:42
DGB:45
DGB:47
DGB:48
DGB:87
DGB:156
ZEC:93
ZEC:193
ZEC:123
ZEC:126
ZEC:153
ZEC:134
ZEC:167
I need to get average of each tag and write to a new file named 24_average
So the 24_average become like this :

24_average:
ZEN:150
ZEC:95
DGB:45
ETH:100
Have no idea how to do it
Any one can help me please.
1.open the file in read mode
2. create empty dict (hint: use defaultdict from collections).
3. iterate over lines of the file and parse each line and add the information to the dict created in 2
4. Once the file has been read in the dict - open new file in write mode, calculate average for each key and write to new file
Thanks a lot buran
will do it.