Python Separate list to be line by line
up vote
0
down vote
favorite
I'm writing a program to do some statistics on some times. I want the output to look like
11: 4
22: 3
33: 1
instead of
11:4, 22:3, 33:1
because I find it hard to read.
Here is the code I have
#Copy solves here, in seconds, seperated by a comma for each solve
times = [11.9, 14.2, 17.3, 11.2 , 123.4]
#Blank list to copy modified solves into
newtimes =
for time in times:
#Rounds down every time
time = int(time)
#Adds time to new list
newtimes.append(time)
#Sorts list lowest to highest
newtimes.sort()
#Gets length of new list, which is amount of solves
solves = len(newtimes)
#Set longest and shortest solve times
longestSolve = max(newtimes)
shortestSolve = min(newtimes)
timesfreq = {i:newtimes.count(i) for i in newtimes}
print(newtimes)
print(timesfreq)
print(solves)
print("Your longest solve was " + str(longestSolve) + " seconds and your shortest solve was " + str(shortestSolve) + " seconds")
python python-3.x list
add a comment |
up vote
0
down vote
favorite
I'm writing a program to do some statistics on some times. I want the output to look like
11: 4
22: 3
33: 1
instead of
11:4, 22:3, 33:1
because I find it hard to read.
Here is the code I have
#Copy solves here, in seconds, seperated by a comma for each solve
times = [11.9, 14.2, 17.3, 11.2 , 123.4]
#Blank list to copy modified solves into
newtimes =
for time in times:
#Rounds down every time
time = int(time)
#Adds time to new list
newtimes.append(time)
#Sorts list lowest to highest
newtimes.sort()
#Gets length of new list, which is amount of solves
solves = len(newtimes)
#Set longest and shortest solve times
longestSolve = max(newtimes)
shortestSolve = min(newtimes)
timesfreq = {i:newtimes.count(i) for i in newtimes}
print(newtimes)
print(timesfreq)
print(solves)
print("Your longest solve was " + str(longestSolve) + " seconds and your shortest solve was " + str(shortestSolve) + " seconds")
python python-3.x list
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm writing a program to do some statistics on some times. I want the output to look like
11: 4
22: 3
33: 1
instead of
11:4, 22:3, 33:1
because I find it hard to read.
Here is the code I have
#Copy solves here, in seconds, seperated by a comma for each solve
times = [11.9, 14.2, 17.3, 11.2 , 123.4]
#Blank list to copy modified solves into
newtimes =
for time in times:
#Rounds down every time
time = int(time)
#Adds time to new list
newtimes.append(time)
#Sorts list lowest to highest
newtimes.sort()
#Gets length of new list, which is amount of solves
solves = len(newtimes)
#Set longest and shortest solve times
longestSolve = max(newtimes)
shortestSolve = min(newtimes)
timesfreq = {i:newtimes.count(i) for i in newtimes}
print(newtimes)
print(timesfreq)
print(solves)
print("Your longest solve was " + str(longestSolve) + " seconds and your shortest solve was " + str(shortestSolve) + " seconds")
python python-3.x list
I'm writing a program to do some statistics on some times. I want the output to look like
11: 4
22: 3
33: 1
instead of
11:4, 22:3, 33:1
because I find it hard to read.
Here is the code I have
#Copy solves here, in seconds, seperated by a comma for each solve
times = [11.9, 14.2, 17.3, 11.2 , 123.4]
#Blank list to copy modified solves into
newtimes =
for time in times:
#Rounds down every time
time = int(time)
#Adds time to new list
newtimes.append(time)
#Sorts list lowest to highest
newtimes.sort()
#Gets length of new list, which is amount of solves
solves = len(newtimes)
#Set longest and shortest solve times
longestSolve = max(newtimes)
shortestSolve = min(newtimes)
timesfreq = {i:newtimes.count(i) for i in newtimes}
print(newtimes)
print(timesfreq)
print(solves)
print("Your longest solve was " + str(longestSolve) + " seconds and your shortest solve was " + str(shortestSolve) + " seconds")
python python-3.x list
python python-3.x list
asked Nov 10 at 22:25
Joel Banks
395
395
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
accepted
just go like this:
for i in timesfreq.items():
print(i)
This gives
(11, 2)
(14, 1)
(17, 1)
(123, 1)
If you want it exactly as you stated:
for a,b in timesfreq.items():
print("{}: {}".format(a,b))
1
Perfect solution! I'm still a beginner so sorry if this was an easy question, but this is exactly what I wanted!
– Joel Banks
Nov 10 at 22:51
add a comment |
up vote
0
down vote
One way you can do this as a one-liner:
>>> print('n'.join([str(key) + ': ' + str(val) for key, val in timesfreq.items()]))
123: 1
17: 1
11: 2
14: 1
Here's a good reference for iterating over key/value pairs in a dictionary: Iterating over dictionaries using 'for' loops
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
just go like this:
for i in timesfreq.items():
print(i)
This gives
(11, 2)
(14, 1)
(17, 1)
(123, 1)
If you want it exactly as you stated:
for a,b in timesfreq.items():
print("{}: {}".format(a,b))
1
Perfect solution! I'm still a beginner so sorry if this was an easy question, but this is exactly what I wanted!
– Joel Banks
Nov 10 at 22:51
add a comment |
up vote
0
down vote
accepted
just go like this:
for i in timesfreq.items():
print(i)
This gives
(11, 2)
(14, 1)
(17, 1)
(123, 1)
If you want it exactly as you stated:
for a,b in timesfreq.items():
print("{}: {}".format(a,b))
1
Perfect solution! I'm still a beginner so sorry if this was an easy question, but this is exactly what I wanted!
– Joel Banks
Nov 10 at 22:51
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
just go like this:
for i in timesfreq.items():
print(i)
This gives
(11, 2)
(14, 1)
(17, 1)
(123, 1)
If you want it exactly as you stated:
for a,b in timesfreq.items():
print("{}: {}".format(a,b))
just go like this:
for i in timesfreq.items():
print(i)
This gives
(11, 2)
(14, 1)
(17, 1)
(123, 1)
If you want it exactly as you stated:
for a,b in timesfreq.items():
print("{}: {}".format(a,b))
answered Nov 10 at 22:39
Christian Sloper
1,024213
1,024213
1
Perfect solution! I'm still a beginner so sorry if this was an easy question, but this is exactly what I wanted!
– Joel Banks
Nov 10 at 22:51
add a comment |
1
Perfect solution! I'm still a beginner so sorry if this was an easy question, but this is exactly what I wanted!
– Joel Banks
Nov 10 at 22:51
1
1
Perfect solution! I'm still a beginner so sorry if this was an easy question, but this is exactly what I wanted!
– Joel Banks
Nov 10 at 22:51
Perfect solution! I'm still a beginner so sorry if this was an easy question, but this is exactly what I wanted!
– Joel Banks
Nov 10 at 22:51
add a comment |
up vote
0
down vote
One way you can do this as a one-liner:
>>> print('n'.join([str(key) + ': ' + str(val) for key, val in timesfreq.items()]))
123: 1
17: 1
11: 2
14: 1
Here's a good reference for iterating over key/value pairs in a dictionary: Iterating over dictionaries using 'for' loops
add a comment |
up vote
0
down vote
One way you can do this as a one-liner:
>>> print('n'.join([str(key) + ': ' + str(val) for key, val in timesfreq.items()]))
123: 1
17: 1
11: 2
14: 1
Here's a good reference for iterating over key/value pairs in a dictionary: Iterating over dictionaries using 'for' loops
add a comment |
up vote
0
down vote
up vote
0
down vote
One way you can do this as a one-liner:
>>> print('n'.join([str(key) + ': ' + str(val) for key, val in timesfreq.items()]))
123: 1
17: 1
11: 2
14: 1
Here's a good reference for iterating over key/value pairs in a dictionary: Iterating over dictionaries using 'for' loops
One way you can do this as a one-liner:
>>> print('n'.join([str(key) + ': ' + str(val) for key, val in timesfreq.items()]))
123: 1
17: 1
11: 2
14: 1
Here's a good reference for iterating over key/value pairs in a dictionary: Iterating over dictionaries using 'for' loops
answered Nov 10 at 22:40
Mixolydian
613
613
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53244030%2fpython-separate-list-to-be-line-by-line%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown