Home > OS >  how to flip characters 90 degrees python?
how to flip characters 90 degrees python?

Time:06-11

I want to flip the given value by 90 degrees, how do I do that? in text.txt:

    == =  
      = ==

In:
    == =  
      = ==

Out:
      =
      =
    =  
      =
    =  
    =  

my code:

w = text.txt
for i in zip(*w):
    t = i[::-1]
print(t)

CodePudding user response:

If you have a text file like:

== =  
  = ==

at path, then you can just open it and pass the filehandle to zip:

with open(path) as f:
    for t in zip(*f):
        print(*reversed(t))

This will print:

  =
  =
=  
  =
=  
=  

CodePudding user response:

I'm presuming you're really new at this let's start off with an answer. There are other ways of doing this.

in_1 = "== =  "
in_2 = "  = =="

for i in range(0,len(in_1)):
  print (in_2[i], in_1[i])

This returns:

enter image description here

Now, that presumes you're just passing in a string and not getting some input from the user. Or bringing in a file as Mark went with.

And that brings us to the second point of asking better questions so you can get better answers. You can tell people want to help. But generally, for that to go well you should be telling a bit more. A big one is what you would expect, and what you provided. Another is either what you've researched, some code you've tried, or an error message.

  • Related